blob: d97554eedc19d1bcc7a93e5b9a70b40d43427056 [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
Wale Ogunwalef75962a2017-08-23 14:58:04 -070019import static android.app.WindowConfiguration.WINDOWING_MODE_DOCKED;
20import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
21import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
22import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
23import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
24
Svet Ganov019d2302015-05-04 11:07:38 -070025import android.Manifest;
Michal Karpinski3da5c972015-12-11 18:16:30 +000026import android.annotation.IntDef;
Dianne Hackbornaec68bb2014-08-20 15:25:13 -070027import android.annotation.NonNull;
28import android.annotation.Nullable;
Svet Ganov019d2302015-05-04 11:07:38 -070029import android.annotation.RequiresPermission;
Amith Yamasani0e8d7d62014-09-03 13:17:28 -070030import android.annotation.SystemApi;
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060031import android.annotation.SystemService;
Dianne Hackborn058f1e42016-11-02 17:18:35 -070032import android.annotation.TestApi;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import android.content.ComponentName;
34import android.content.Context;
35import android.content.Intent;
Felipe Lemef3fa0f82016-01-07 12:08:19 -080036import android.content.UriPermission;
Wale Ogunwalec981ad52017-06-13 11:40:06 -070037import android.content.pm.ActivityInfo;
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -070038import android.content.pm.ApplicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039import android.content.pm.ConfigurationInfo;
40import android.content.pm.IPackageDataObserver;
Dianne Hackborn5320eb82012-05-18 12:05:04 -070041import android.content.pm.PackageManager;
Felipe Lemef3fa0f82016-01-07 12:08:19 -080042import android.content.pm.ParceledListSlice;
Dianne Hackborn41203752012-08-31 14:05:51 -070043import android.content.pm.UserInfo;
Wale Ogunwalec981ad52017-06-13 11:40:06 -070044import android.content.res.Configuration;
Kenny Root5ef44b72011-01-26 17:22:20 -080045import android.content.res.Resources;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046import android.graphics.Bitmap;
Wale Ogunwalec981ad52017-06-13 11:40:06 -070047import android.graphics.Canvas;
Winson Chunga449dc02014-05-16 11:15:04 -070048import android.graphics.Color;
Wale Ogunwalec981ad52017-06-13 11:40:06 -070049import android.graphics.GraphicBuffer;
50import android.graphics.Matrix;
51import android.graphics.Point;
Craig Mautner967212c2013-04-13 21:10:58 -070052import android.graphics.Rect;
Wale Ogunwalec981ad52017-06-13 11:40:06 -070053import android.os.BatteryStats;
54import android.os.Build;
55import android.os.Build.VERSION_CODES;
Dianne Hackborn8078d8c2012-03-20 11:11:26 -070056import android.os.Bundle;
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -070057import android.os.Debug;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058import android.os.Handler;
Wale Ogunwalec981ad52017-06-13 11:40:06 -070059import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060import android.os.Parcel;
Wale Ogunwalec981ad52017-06-13 11:40:06 -070061import android.os.ParcelFileDescriptor;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062import android.os.Parcelable;
Dianne Hackborn5320eb82012-05-18 12:05:04 -070063import android.os.Process;
Amith Yamasani4b2e9342011-03-31 12:38:53 -070064import android.os.RemoteException;
Peter Visontay8d224ca2011-02-18 16:39:19 +000065import android.os.ServiceManager;
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -070066import android.os.SystemProperties;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070067import android.os.UserHandle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068import android.text.TextUtils;
Dianne Hackborn058f1e42016-11-02 17:18:35 -070069import android.util.ArrayMap;
Kenny Root5ef44b72011-01-26 17:22:20 -080070import android.util.DisplayMetrics;
Sudheer Shankafc46e9b2016-10-21 17:55:27 -070071import android.util.Singleton;
Winson Chung48a10a52014-08-27 14:36:51 -070072import android.util.Size;
Felipe Lemef3fa0f82016-01-07 12:08:19 -080073
Wale Ogunwalec981ad52017-06-13 11:40:06 -070074import com.android.internal.app.procstats.ProcessStats;
75import com.android.internal.os.RoSystemProperties;
76import com.android.internal.os.TransferPipe;
77import com.android.internal.util.FastPrintWriter;
78import com.android.server.LocalServices;
79
Craig Mautner648f69b2014-09-18 14:16:26 -070080import org.xmlpull.v1.XmlSerializer;
Kenny Root5ef44b72011-01-26 17:22:20 -080081
Dianne Hackborncbfd23e2013-06-11 14:26:53 -070082import java.io.FileDescriptor;
83import java.io.FileOutputStream;
Craig Mautner648f69b2014-09-18 14:16:26 -070084import java.io.IOException;
Dianne Hackborncbfd23e2013-06-11 14:26:53 -070085import java.io.PrintWriter;
Michal Karpinski3da5c972015-12-11 18:16:30 +000086import java.lang.annotation.Retention;
87import java.lang.annotation.RetentionPolicy;
Winson Chung1147c402014-05-14 11:05:00 -070088import java.util.ArrayList;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089import java.util.List;
90
91/**
Dave Friedman2a3ebad2017-01-04 18:27:26 -080092 * <p>
93 * This class gives information about, and interacts
94 * with, activities, services, and the containing
95 * process.
96 * </p>
97 *
98 * <p>
99 * A number of the methods in this class are for
100 * debugging or informational purposes and they should
101 * not be used to affect any runtime behavior of
102 * your app. These methods are called out as such in
103 * the method level documentation.
104 * </p>
105 *
106 *<p>
107 * Most application developers should not have the need to
108 * use this class, most of whose methods are for specialized
109 * use cases. However, a few methods are more broadly applicable.
110 * For instance, {@link android.app.ActivityManager#isLowRamDevice() isLowRamDevice()}
111 * enables your app to detect whether it is running on a low-memory device,
112 * and behave accordingly.
113 * {@link android.app.ActivityManager#clearApplicationUserData() clearApplicationUserData()}
114 * is for apps with reset-data functionality.
115 * </p>
116 *
117 * <p>
118 * In some special use cases, where an app interacts with
119 * its Task stack, the app may use the
120 * {@link android.app.ActivityManager.AppTask} and
121 * {@link android.app.ActivityManager.RecentTaskInfo} inner
122 * classes. However, in general, the methods in this class should
123 * be used for testing and debugging purposes only.
124 * </p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -0600126@SystemService(Context.ACTIVITY_SERVICE)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127public class ActivityManager {
128 private static String TAG = "ActivityManager";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800129
Dianne Hackborn852975d2014-08-22 17:42:43 -0700130 private static int gMaxRecentTasks = -1;
131
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132 private final Context mContext;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800133
Sudheer Shankadc589ac2016-11-10 15:30:17 -0800134 private static volatile boolean sSystemReady = false;
135
Bryce Lee7f936862017-05-09 15:33:18 -0700136
137 private static final int FIRST_START_FATAL_ERROR_CODE = -100;
138 private static final int LAST_START_FATAL_ERROR_CODE = -1;
139 private static final int FIRST_START_SUCCESS_CODE = 0;
140 private static final int LAST_START_SUCCESS_CODE = 99;
141 private static final int FIRST_START_NON_FATAL_ERROR_CODE = 100;
142 private static final int LAST_START_NON_FATAL_ERROR_CODE = 199;
143
Jorim Jaggi02886a82016-12-06 09:10:06 -0800144 /**
145 * System property to enable task snapshots.
146 * @hide
147 */
148 public final static boolean ENABLE_TASK_SNAPSHOTS;
149
150 static {
Robert Carra35e5de2017-03-03 17:04:54 -0800151 ENABLE_TASK_SNAPSHOTS = SystemProperties.getBoolean("persist.enable_task_snapshots", true);
Jorim Jaggi02886a82016-12-06 09:10:06 -0800152 }
153
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700154 static final class UidObserver extends IUidObserver.Stub {
155 final OnUidImportanceListener mListener;
Makoto Onukid7e40582017-04-13 14:54:56 -0700156 final Context mContext;
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700157
Makoto Onukid7e40582017-04-13 14:54:56 -0700158 UidObserver(OnUidImportanceListener listener, Context clientContext) {
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700159 mListener = listener;
Makoto Onukid7e40582017-04-13 14:54:56 -0700160 mContext = clientContext;
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700161 }
162
163 @Override
Sudheer Shanka80255802017-03-04 14:48:53 -0800164 public void onUidStateChanged(int uid, int procState, long procStateSeq) {
Makoto Onukid7e40582017-04-13 14:54:56 -0700165 mListener.onUidImportance(uid, RunningAppProcessInfo.procStateToImportanceForClient(
166 procState, mContext));
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700167 }
168
169 @Override
Dianne Hackborne07641d2016-11-09 15:07:23 -0800170 public void onUidGone(int uid, boolean disabled) {
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700171 mListener.onUidImportance(uid, RunningAppProcessInfo.IMPORTANCE_GONE);
172 }
173
174 @Override
175 public void onUidActive(int uid) {
176 }
177
178 @Override
Dianne Hackborne07641d2016-11-09 15:07:23 -0800179 public void onUidIdle(int uid, boolean disabled) {
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700180 }
Dianne Hackborn3e99f652017-07-05 16:33:56 -0700181
182 @Override public void onUidCachedChanged(int uid, boolean cached) {
183 }
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700184 }
185
186 final ArrayMap<OnUidImportanceListener, UidObserver> mImportanceListeners = new ArrayMap<>();
187
Felipe Lemedc7af962016-01-22 18:27:03 -0800188 /**
189 * Defines acceptable types of bugreports.
190 * @hide
191 */
Michal Karpinski3da5c972015-12-11 18:16:30 +0000192 @Retention(RetentionPolicy.SOURCE)
193 @IntDef({
194 BUGREPORT_OPTION_FULL,
195 BUGREPORT_OPTION_INTERACTIVE,
Wei Liu967fc8d2016-07-08 11:44:20 -0700196 BUGREPORT_OPTION_REMOTE,
Felipe Leme9606c3b2017-01-05 14:57:12 -0800197 BUGREPORT_OPTION_WEAR,
198 BUGREPORT_OPTION_TELEPHONY
Michal Karpinski3da5c972015-12-11 18:16:30 +0000199 })
Michal Karpinski3da5c972015-12-11 18:16:30 +0000200 public @interface BugreportMode {}
201 /**
202 * Takes a bugreport without user interference (and hence causing less
203 * interference to the system), but includes all sections.
204 * @hide
205 */
206 public static final int BUGREPORT_OPTION_FULL = 0;
207 /**
208 * Allows user to monitor progress and enter additional data; might not include all
209 * sections.
210 * @hide
211 */
212 public static final int BUGREPORT_OPTION_INTERACTIVE = 1;
213 /**
214 * Takes a bugreport requested remotely by administrator of the Device Owner app,
215 * not the device's user.
216 * @hide
217 */
218 public static final int BUGREPORT_OPTION_REMOTE = 2;
Wei Liu967fc8d2016-07-08 11:44:20 -0700219 /**
220 * Takes a bugreport on a wearable device.
221 * @hide
222 */
223 public static final int BUGREPORT_OPTION_WEAR = 3;
Michal Karpinski3da5c972015-12-11 18:16:30 +0000224
Dianne Hackborna4972e92012-03-14 10:38:05 -0700225 /**
Felipe Leme9606c3b2017-01-05 14:57:12 -0800226 * Takes a lightweight version of bugreport that only includes a few, urgent sections
227 * used to report telephony bugs.
228 * @hide
229 */
230 public static final int BUGREPORT_OPTION_TELEPHONY = 4;
231
232 /**
Scott Maincc2195b2013-10-16 13:57:46 -0700233 * <a href="{@docRoot}guide/topics/manifest/meta-data-element.html">{@code
Neil Fuller71fbb812015-11-30 09:51:33 +0000234 * <meta-data>}</a> name for a 'home' Activity that declares a package that is to be
Christopher Tatebd413f62013-09-18 18:31:59 -0700235 * uninstalled in lieu of the declaring one. The package named here must be
Neil Fuller71fbb812015-11-30 09:51:33 +0000236 * signed with the same certificate as the one declaring the {@code <meta-data>}.
Christopher Tatebd413f62013-09-18 18:31:59 -0700237 */
238 public static final String META_HOME_ALTERNATE = "android.app.home.alternate";
239
Bryce Lee7f936862017-05-09 15:33:18 -0700240 // NOTE: Before adding a new start result, please reference the defined ranges to ensure the
241 // result is properly categorized.
242
Christopher Tatebd413f62013-09-18 18:31:59 -0700243 /**
Amith Yamasani42449782016-04-19 11:45:51 -0700244 * Result for IActivityManager.startVoiceActivity: active session is currently hidden.
245 * @hide
246 */
Bryce Lee7f936862017-05-09 15:33:18 -0700247 public static final int START_VOICE_HIDDEN_SESSION = FIRST_START_FATAL_ERROR_CODE;
Amith Yamasani42449782016-04-19 11:45:51 -0700248
249 /**
250 * Result for IActivityManager.startVoiceActivity: active session does not match
251 * the requesting token.
252 * @hide
253 */
Bryce Lee7f936862017-05-09 15:33:18 -0700254 public static final int START_VOICE_NOT_ACTIVE_SESSION = FIRST_START_FATAL_ERROR_CODE + 1;
Amith Yamasani42449782016-04-19 11:45:51 -0700255
256 /**
Wale Ogunwale0bd2aa72015-04-16 13:50:44 -0700257 * Result for IActivityManager.startActivity: trying to start a background user
258 * activity that shouldn't be displayed for all users.
259 * @hide
260 */
Bryce Lee7f936862017-05-09 15:33:18 -0700261 public static final int START_NOT_CURRENT_USER_ACTIVITY = FIRST_START_FATAL_ERROR_CODE + 2;
Wale Ogunwale0bd2aa72015-04-16 13:50:44 -0700262
263 /**
Dianne Hackborn91097de2014-04-04 18:02:06 -0700264 * Result for IActivityManager.startActivity: trying to start an activity under voice
265 * control when that activity does not support the VOICE category.
266 * @hide
267 */
Bryce Lee7f936862017-05-09 15:33:18 -0700268 public static final int START_NOT_VOICE_COMPATIBLE = FIRST_START_FATAL_ERROR_CODE + 3;
Dianne Hackborn91097de2014-04-04 18:02:06 -0700269
270 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700271 * Result for IActivityManager.startActivity: an error where the
272 * start had to be canceled.
273 * @hide
274 */
Bryce Lee7f936862017-05-09 15:33:18 -0700275 public static final int START_CANCELED = FIRST_START_FATAL_ERROR_CODE + 4;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700276
277 /**
278 * Result for IActivityManager.startActivity: an error where the
279 * thing being started is not an activity.
280 * @hide
281 */
Bryce Lee7f936862017-05-09 15:33:18 -0700282 public static final int START_NOT_ACTIVITY = FIRST_START_FATAL_ERROR_CODE + 5;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700283
284 /**
285 * Result for IActivityManager.startActivity: an error where the
286 * caller does not have permission to start the activity.
287 * @hide
288 */
Bryce Lee7f936862017-05-09 15:33:18 -0700289 public static final int START_PERMISSION_DENIED = FIRST_START_FATAL_ERROR_CODE + 6;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700290
291 /**
292 * Result for IActivityManager.startActivity: an error where the
293 * caller has requested both to forward a result and to receive
294 * a result.
295 * @hide
296 */
Bryce Lee7f936862017-05-09 15:33:18 -0700297 public static final int START_FORWARD_AND_REQUEST_CONFLICT = FIRST_START_FATAL_ERROR_CODE + 7;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700298
299 /**
300 * Result for IActivityManager.startActivity: an error where the
301 * requested class is not found.
302 * @hide
303 */
Bryce Lee7f936862017-05-09 15:33:18 -0700304 public static final int START_CLASS_NOT_FOUND = FIRST_START_FATAL_ERROR_CODE + 8;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700305
306 /**
307 * Result for IActivityManager.startActivity: an error where the
308 * given Intent could not be resolved to an activity.
309 * @hide
310 */
Bryce Lee7f936862017-05-09 15:33:18 -0700311 public static final int START_INTENT_NOT_RESOLVED = FIRST_START_FATAL_ERROR_CODE + 9;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700312
313 /**
Winson Chungfc3ec4c2017-06-01 15:35:48 -0700314 * Result for IActivityManager.startAssistantActivity: active session is currently hidden.
315 * @hide
316 */
317 public static final int START_ASSISTANT_HIDDEN_SESSION = FIRST_START_FATAL_ERROR_CODE + 10;
318
319 /**
320 * Result for IActivityManager.startAssistantActivity: active session does not match
321 * the requesting token.
322 * @hide
323 */
324 public static final int START_ASSISTANT_NOT_ACTIVE_SESSION = FIRST_START_FATAL_ERROR_CODE + 11;
325
326 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700327 * Result for IActivityManaqer.startActivity: the activity was started
328 * successfully as normal.
329 * @hide
330 */
Bryce Lee7f936862017-05-09 15:33:18 -0700331 public static final int START_SUCCESS = FIRST_START_SUCCESS_CODE;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700332
333 /**
334 * Result for IActivityManaqer.startActivity: the caller asked that the Intent not
335 * be executed if it is the recipient, and that is indeed the case.
336 * @hide
337 */
Bryce Lee7f936862017-05-09 15:33:18 -0700338 public static final int START_RETURN_INTENT_TO_CALLER = FIRST_START_SUCCESS_CODE + 1;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700339
340 /**
341 * Result for IActivityManaqer.startActivity: activity wasn't really started, but
342 * a task was simply brought to the foreground.
343 * @hide
344 */
Bryce Lee7f936862017-05-09 15:33:18 -0700345 public static final int START_TASK_TO_FRONT = FIRST_START_SUCCESS_CODE + 2;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700346
347 /**
348 * Result for IActivityManaqer.startActivity: activity wasn't really started, but
349 * the given Intent was given to the existing top activity.
350 * @hide
351 */
Bryce Lee7f936862017-05-09 15:33:18 -0700352 public static final int START_DELIVERED_TO_TOP = FIRST_START_SUCCESS_CODE + 3;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700353
354 /**
355 * Result for IActivityManaqer.startActivity: request was canceled because
356 * app switches are temporarily canceled to ensure the user's last request
357 * (such as pressing home) is performed.
358 * @hide
359 */
Bryce Lee7f936862017-05-09 15:33:18 -0700360 public static final int START_SWITCHES_CANCELED = FIRST_START_NON_FATAL_ERROR_CODE;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700361
362 /**
Craig Mautneraea74a52014-03-08 14:23:10 -0800363 * Result for IActivityManaqer.startActivity: a new activity was attempted to be started
364 * while in Lock Task Mode.
365 * @hide
366 */
Bryce Lee7f936862017-05-09 15:33:18 -0700367 public static final int START_RETURN_LOCK_TASK_MODE_VIOLATION =
368 FIRST_START_NON_FATAL_ERROR_CODE + 1;
Craig Mautneraea74a52014-03-08 14:23:10 -0800369
370 /**
Bryce Leef9d49542017-06-26 16:27:32 -0700371 * Result for IActivityManaqer.startActivity: a new activity start was aborted. Never returned
372 * externally.
373 * @hide
374 */
375 public static final int START_ABORTED = FIRST_START_NON_FATAL_ERROR_CODE + 2;
376
377 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700378 * Flag for IActivityManaqer.startActivity: do special start mode where
379 * a new activity is launched only if it is needed.
380 * @hide
381 */
382 public static final int START_FLAG_ONLY_IF_NEEDED = 1<<0;
383
384 /**
385 * Flag for IActivityManaqer.startActivity: launch the app for
386 * debugging.
387 * @hide
388 */
389 public static final int START_FLAG_DEBUG = 1<<1;
390
391 /**
392 * Flag for IActivityManaqer.startActivity: launch the app for
Man Caocfa78b22015-06-11 20:14:34 -0700393 * allocation tracking.
394 * @hide
395 */
Pablo Ceballosa4d4e822015-10-05 10:27:52 -0700396 public static final int START_FLAG_TRACK_ALLOCATION = 1<<2;
Man Caocfa78b22015-06-11 20:14:34 -0700397
398 /**
Tamas Berghammerdf6cb282016-01-29 12:07:00 +0000399 * Flag for IActivityManaqer.startActivity: launch the app with
400 * native debugging support.
401 * @hide
402 */
403 public static final int START_FLAG_NATIVE_DEBUGGING = 1<<3;
404
405 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700406 * Result for IActivityManaqer.broadcastIntent: success!
407 * @hide
408 */
409 public static final int BROADCAST_SUCCESS = 0;
410
411 /**
412 * Result for IActivityManaqer.broadcastIntent: attempt to broadcast
413 * a sticky intent without appropriate permission.
414 * @hide
415 */
416 public static final int BROADCAST_STICKY_CANT_HAVE_PERMISSION = -1;
417
418 /**
Amith Yamasani83b6ef02014-11-07 15:34:04 -0800419 * Result for IActivityManager.broadcastIntent: trying to send a broadcast
420 * to a stopped user. Fail.
421 * @hide
422 */
423 public static final int BROADCAST_FAILED_USER_STOPPED = -2;
424
425 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700426 * Type for IActivityManaqer.getIntentSender: this PendingIntent is
427 * for a sendBroadcast operation.
428 * @hide
429 */
430 public static final int INTENT_SENDER_BROADCAST = 1;
431
432 /**
433 * Type for IActivityManaqer.getIntentSender: this PendingIntent is
434 * for a startActivity operation.
435 * @hide
436 */
437 public static final int INTENT_SENDER_ACTIVITY = 2;
438
439 /**
440 * Type for IActivityManaqer.getIntentSender: this PendingIntent is
441 * for an activity result operation.
442 * @hide
443 */
444 public static final int INTENT_SENDER_ACTIVITY_RESULT = 3;
445
446 /**
447 * Type for IActivityManaqer.getIntentSender: this PendingIntent is
448 * for a startService operation.
449 * @hide
450 */
451 public static final int INTENT_SENDER_SERVICE = 4;
452
Christopher Tate08992ac2017-03-21 11:37:06 -0700453 /**
454 * Type for IActivityManaqer.getIntentSender: this PendingIntent is
455 * for a startForegroundService operation.
456 * @hide
457 */
458 public static final int INTENT_SENDER_FOREGROUND_SERVICE = 5;
459
Dianne Hackborn80a4af22012-08-27 19:18:31 -0700460 /** @hide User operation call: success! */
461 public static final int USER_OP_SUCCESS = 0;
462
463 /** @hide User operation call: given user id is not known. */
464 public static final int USER_OP_UNKNOWN_USER = -1;
465
466 /** @hide User operation call: given user id is the current user, can't be stopped. */
467 public static final int USER_OP_IS_CURRENT = -2;
468
Fyodor Kupolov9cbfc9e2015-10-07 15:52:33 -0700469 /** @hide User operation call: system user can't be stopped. */
470 public static final int USER_OP_ERROR_IS_SYSTEM = -3;
471
472 /** @hide User operation call: one of related users cannot be stopped. */
473 public static final int USER_OP_ERROR_RELATED_USERS_CANNOT_STOP = -4;
474
Dianne Hackborn5614bf52016-11-07 17:26:41 -0800475 /** @hide Not a real process state. */
476 public static final int PROCESS_STATE_UNKNOWN = -1;
Ruben Brunka27eef42015-01-28 15:04:16 -0800477
Dianne Hackborna413dc02013-07-12 12:02:55 -0700478 /** @hide Process is a persistent system process. */
479 public static final int PROCESS_STATE_PERSISTENT = 0;
480
481 /** @hide Process is a persistent system process and is doing UI. */
482 public static final int PROCESS_STATE_PERSISTENT_UI = 1;
483
Dianne Hackbornc8230512013-07-13 21:32:12 -0700484 /** @hide Process is hosting the current top activities. Note that this covers
485 * all activities that are visible to the user. */
Dianne Hackborna413dc02013-07-12 12:02:55 -0700486 public static final int PROCESS_STATE_TOP = 2;
487
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700488 /** @hide Process is hosting a foreground service due to a system binding. */
489 public static final int PROCESS_STATE_BOUND_FOREGROUND_SERVICE = 3;
490
Dianne Hackborn4870e9d2015-04-08 16:55:47 -0700491 /** @hide Process is hosting a foreground service. */
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700492 public static final int PROCESS_STATE_FOREGROUND_SERVICE = 4;
Dianne Hackborn4870e9d2015-04-08 16:55:47 -0700493
494 /** @hide Same as {@link #PROCESS_STATE_TOP} but while device is sleeping. */
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700495 public static final int PROCESS_STATE_TOP_SLEEPING = 5;
Dianne Hackborn4870e9d2015-04-08 16:55:47 -0700496
Dianne Hackborna413dc02013-07-12 12:02:55 -0700497 /** @hide Process is important to the user, and something they are aware of. */
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700498 public static final int PROCESS_STATE_IMPORTANT_FOREGROUND = 6;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700499
500 /** @hide Process is important to the user, but not something they are aware of. */
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700501 public static final int PROCESS_STATE_IMPORTANT_BACKGROUND = 7;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700502
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700503 /** @hide Process is in the background transient so we will try to keep running. */
504 public static final int PROCESS_STATE_TRANSIENT_BACKGROUND = 8;
505
Dianne Hackborna413dc02013-07-12 12:02:55 -0700506 /** @hide Process is in the background running a backup/restore operation. */
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700507 public static final int PROCESS_STATE_BACKUP = 9;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700508
Dianne Hackbornc8230512013-07-13 21:32:12 -0700509 /** @hide Process is in the background, but it can't restore its state so we want
510 * to try to avoid killing it. */
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700511 public static final int PROCESS_STATE_HEAVY_WEIGHT = 10;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700512
513 /** @hide Process is in the background running a service. Unlike oom_adj, this level
514 * is used for both the normal running in background state and the executing
515 * operations state. */
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700516 public static final int PROCESS_STATE_SERVICE = 11;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700517
Dianne Hackbornc8230512013-07-13 21:32:12 -0700518 /** @hide Process is in the background running a receiver. Note that from the
519 * perspective of oom_adj receivers run at a higher foreground level, but for our
520 * prioritization here that is not necessary and putting them below services means
521 * many fewer changes in some process states as they receive broadcasts. */
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700522 public static final int PROCESS_STATE_RECEIVER = 12;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700523
Dianne Hackborna413dc02013-07-12 12:02:55 -0700524 /** @hide Process is in the background but hosts the home activity. */
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700525 public static final int PROCESS_STATE_HOME = 13;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700526
527 /** @hide Process is in the background but hosts the last shown activity. */
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700528 public static final int PROCESS_STATE_LAST_ACTIVITY = 14;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700529
Dianne Hackbornc8230512013-07-13 21:32:12 -0700530 /** @hide Process is being cached for later use and contains activities. */
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700531 public static final int PROCESS_STATE_CACHED_ACTIVITY = 15;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700532
533 /** @hide Process is being cached for later use and is a client of another cached
534 * process that contains activities. */
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700535 public static final int PROCESS_STATE_CACHED_ACTIVITY_CLIENT = 16;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700536
537 /** @hide Process is being cached for later use and is empty. */
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700538 public static final int PROCESS_STATE_CACHED_EMPTY = 17;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700539
Dianne Hackborn5614bf52016-11-07 17:26:41 -0800540 /** @hide Process does not exist. */
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700541 public static final int PROCESS_STATE_NONEXISTENT = 18;
Dianne Hackborn5614bf52016-11-07 17:26:41 -0800542
Joe Onorato05c9ecc2016-03-30 15:13:46 -0700543 /** @hide The lowest process state number */
Dianne Hackborn5614bf52016-11-07 17:26:41 -0800544 public static final int MIN_PROCESS_STATE = PROCESS_STATE_PERSISTENT;
Joe Onorato05c9ecc2016-03-30 15:13:46 -0700545
546 /** @hide The highest process state number */
Dianne Hackborn5614bf52016-11-07 17:26:41 -0800547 public static final int MAX_PROCESS_STATE = PROCESS_STATE_NONEXISTENT;
Joe Onorato05c9ecc2016-03-30 15:13:46 -0700548
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700549 /** @hide Should this process state be considered a background state? */
550 public static final boolean isProcStateBackground(int procState) {
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700551 return procState >= PROCESS_STATE_TRANSIENT_BACKGROUND;
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700552 }
553
Dianne Hackborna83ce1d2015-03-11 15:16:13 -0700554 /** @hide requestType for assist context: only basic information. */
555 public static final int ASSIST_CONTEXT_BASIC = 0;
556
557 /** @hide requestType for assist context: generate full AssistStructure. */
558 public static final int ASSIST_CONTEXT_FULL = 1;
559
Felipe Leme640f30a2017-03-06 15:44:06 -0800560 /** @hide requestType for assist context: generate full AssistStructure for autofill. */
561 public static final int ASSIST_CONTEXT_AUTOFILL = 2;
Felipe Leme6d553872016-12-08 17:13:25 -0800562
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700563 /** @hide Flag for registerUidObserver: report changes in process state. */
564 public static final int UID_OBSERVER_PROCSTATE = 1<<0;
565
566 /** @hide Flag for registerUidObserver: report uid gone. */
567 public static final int UID_OBSERVER_GONE = 1<<1;
568
569 /** @hide Flag for registerUidObserver: report uid has become idle. */
570 public static final int UID_OBSERVER_IDLE = 1<<2;
571
572 /** @hide Flag for registerUidObserver: report uid has become active. */
573 public static final int UID_OBSERVER_ACTIVE = 1<<3;
574
Dianne Hackborn3e99f652017-07-05 16:33:56 -0700575 /** @hide Flag for registerUidObserver: report uid cached state has changed. */
576 public static final int UID_OBSERVER_CACHED = 1<<4;
577
Dianne Hackbornc3af19a2017-01-20 17:00:44 -0800578 /** @hide Mode for {@link IActivityManager#isAppStartModeDisabled}: normal free-to-run operation. */
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700579 public static final int APP_START_MODE_NORMAL = 0;
580
Dianne Hackbornc3af19a2017-01-20 17:00:44 -0800581 /** @hide Mode for {@link IActivityManager#isAppStartModeDisabled}: delay running until later. */
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700582 public static final int APP_START_MODE_DELAYED = 1;
583
Dianne Hackbornc3af19a2017-01-20 17:00:44 -0800584 /** @hide Mode for {@link IActivityManager#isAppStartModeDisabled}: delay running until later, with
Dianne Hackborn85e35642017-01-12 15:10:57 -0800585 * rigid errors (throwing exception). */
586 public static final int APP_START_MODE_DELAYED_RIGID = 2;
587
Dianne Hackbornc3af19a2017-01-20 17:00:44 -0800588 /** @hide Mode for {@link IActivityManager#isAppStartModeDisabled}: disable/cancel pending
Dianne Hackborn85e35642017-01-12 15:10:57 -0800589 * launches; this is the mode for ephemeral apps. */
590 public static final int APP_START_MODE_DISABLED = 3;
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700591
Benjamin Franz43261142015-02-11 15:59:44 +0000592 /**
593 * Lock task mode is not active.
594 */
595 public static final int LOCK_TASK_MODE_NONE = 0;
596
597 /**
598 * Full lock task mode is active.
599 */
600 public static final int LOCK_TASK_MODE_LOCKED = 1;
601
602 /**
603 * App pinning mode is active.
604 */
605 public static final int LOCK_TASK_MODE_PINNED = 2;
606
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700607 Point mAppTaskThumbnailSize;
608
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800609 /*package*/ ActivityManager(Context context, Handler handler) {
610 mContext = context;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800611 }
612
613 /**
Bryce Lee7f936862017-05-09 15:33:18 -0700614 * Returns whether the launch was successful.
615 * @hide
616 */
617 public static final boolean isStartResultSuccessful(int result) {
618 return FIRST_START_SUCCESS_CODE <= result && result <= LAST_START_SUCCESS_CODE;
619 }
620
621 /**
622 * Returns whether the launch result was a fatal error.
623 * @hide
624 */
625 public static final boolean isStartResultFatalError(int result) {
626 return FIRST_START_FATAL_ERROR_CODE <= result && result <= LAST_START_FATAL_ERROR_CODE;
627 }
628
629 /**
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700630 * Screen compatibility mode: the application most always run in
631 * compatibility mode.
632 * @hide
633 */
634 public static final int COMPAT_MODE_ALWAYS = -1;
635
636 /**
637 * Screen compatibility mode: the application can never run in
638 * compatibility mode.
639 * @hide
640 */
641 public static final int COMPAT_MODE_NEVER = -2;
642
643 /**
644 * Screen compatibility mode: unknown.
645 * @hide
646 */
647 public static final int COMPAT_MODE_UNKNOWN = -3;
648
649 /**
650 * Screen compatibility mode: the application currently has compatibility
651 * mode disabled.
652 * @hide
653 */
654 public static final int COMPAT_MODE_DISABLED = 0;
655
656 /**
657 * Screen compatibility mode: the application currently has compatibility
658 * mode enabled.
659 * @hide
660 */
661 public static final int COMPAT_MODE_ENABLED = 1;
662
663 /**
664 * Screen compatibility mode: request to toggle the application's
665 * compatibility mode.
666 * @hide
667 */
668 public static final int COMPAT_MODE_TOGGLE = 2;
669
Marc Hittinger17fb5962017-04-05 15:34:38 -0700670 private static final boolean DEVELOPMENT_FORCE_LOW_RAM =
671 SystemProperties.getBoolean("debug.force_low_ram", false);
672
Wale Ogunwale3797c222015-10-27 14:21:58 -0700673 /** @hide */
674 public static class StackId {
675 /** Invalid stack ID. */
676 public static final int INVALID_STACK_ID = -1;
Chong Zhang5dcb2752015-08-18 13:50:26 -0700677
Wale Ogunwale3797c222015-10-27 14:21:58 -0700678 /** First static stack ID. */
679 public static final int FIRST_STATIC_STACK_ID = 0;
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700680
Wale Ogunwale3797c222015-10-27 14:21:58 -0700681 /** Home activity stack ID. */
682 public static final int HOME_STACK_ID = FIRST_STATIC_STACK_ID;
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700683
Wale Ogunwale3797c222015-10-27 14:21:58 -0700684 /** ID of stack where fullscreen activities are normally launched into. */
685 public static final int FULLSCREEN_WORKSPACE_STACK_ID = 1;
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700686
Wale Ogunwale3797c222015-10-27 14:21:58 -0700687 /** ID of stack where freeform/resized activities are normally launched into. */
688 public static final int FREEFORM_WORKSPACE_STACK_ID = FULLSCREEN_WORKSPACE_STACK_ID + 1;
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700689
Wale Ogunwale3797c222015-10-27 14:21:58 -0700690 /** ID of stack that occupies a dedicated region of the screen. */
691 public static final int DOCKED_STACK_ID = FREEFORM_WORKSPACE_STACK_ID + 1;
Wale Ogunwaleb34a7ad2015-08-14 11:05:30 -0700692
Wale Ogunwale3797c222015-10-27 14:21:58 -0700693 /** ID of stack that always on top (always visible) when it exist. */
694 public static final int PINNED_STACK_ID = DOCKED_STACK_ID + 1;
Wale Ogunwale99db1862015-10-23 20:08:22 -0700695
Winson Chung83471632016-12-13 11:02:12 -0800696 /** ID of stack that contains the Recents activity. */
Matthew Ngae1ff4f2016-11-10 15:49:14 -0800697 public static final int RECENTS_STACK_ID = PINNED_STACK_ID + 1;
698
Winson Chung83471632016-12-13 11:02:12 -0800699 /** ID of stack that contains activities launched by the assistant. */
700 public static final int ASSISTANT_STACK_ID = RECENTS_STACK_ID + 1;
701
Wale Ogunwale3797c222015-10-27 14:21:58 -0700702 /** Last static stack stack ID. */
Winson Chung83471632016-12-13 11:02:12 -0800703 public static final int LAST_STATIC_STACK_ID = ASSISTANT_STACK_ID;
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700704
Wale Ogunwale3797c222015-10-27 14:21:58 -0700705 /** Start of ID range used by stacks that are created dynamically. */
706 public static final int FIRST_DYNAMIC_STACK_ID = LAST_STATIC_STACK_ID + 1;
707
Wale Ogunwale3382ab12017-07-27 08:55:03 -0700708 // TODO: Figure-out a way to remove this.
Wale Ogunwale3797c222015-10-27 14:21:58 -0700709 public static boolean isStaticStack(int stackId) {
710 return stackId >= FIRST_STATIC_STACK_ID && stackId <= LAST_STATIC_STACK_ID;
711 }
712
Wale Ogunwale3382ab12017-07-27 08:55:03 -0700713 // TODO: It seems this mostly means a stack on a secondary display now. Need to see if
714 // there are other meanings. If not why not just use information from the display?
Andrii Kulian4ede3e02017-01-12 11:52:31 -0800715 public static boolean isDynamicStack(int stackId) {
716 return stackId >= FIRST_DYNAMIC_STACK_ID;
717 }
718
Wale Ogunwale3797c222015-10-27 14:21:58 -0700719 /**
Wale Ogunwale3797c222015-10-27 14:21:58 -0700720 * Returns true if dynamic stacks are allowed to be visible behind the input stack.
721 */
Wale Ogunwale3382ab12017-07-27 08:55:03 -0700722 // TODO: Figure-out a way to remove.
Wale Ogunwale3797c222015-10-27 14:21:58 -0700723 public static boolean isDynamicStacksVisibleBehindAllowed(int stackId) {
Winson Chung83471632016-12-13 11:02:12 -0800724 return stackId == PINNED_STACK_ID || stackId == ASSISTANT_STACK_ID;
Wale Ogunwale3797c222015-10-27 14:21:58 -0700725 }
726
727 /**
728 * Returns true if we try to maintain focus in the current stack when the top activity
729 * finishes.
730 */
Wale Ogunwale3382ab12017-07-27 08:55:03 -0700731 // TODO: Figure-out a way to remove. Probably isn't needed in the new world...
Wale Ogunwale3797c222015-10-27 14:21:58 -0700732 public static boolean keepFocusInStackIfPossible(int stackId) {
733 return stackId == FREEFORM_WORKSPACE_STACK_ID
734 || stackId == DOCKED_STACK_ID || stackId == PINNED_STACK_ID;
735 }
736
737 /**
738 * Returns true if Stack size is affected by the docked stack changing size.
739 */
Wale Ogunwale3382ab12017-07-27 08:55:03 -0700740 // TODO: Figure-out a way to remove.
Wale Ogunwale3797c222015-10-27 14:21:58 -0700741 public static boolean isResizeableByDockedStack(int stackId) {
Winson Chung83471632016-12-13 11:02:12 -0800742 return isStaticStack(stackId) && stackId != DOCKED_STACK_ID
743 && stackId != PINNED_STACK_ID && stackId != ASSISTANT_STACK_ID;
Wale Ogunwale3797c222015-10-27 14:21:58 -0700744 }
745
746 /**
747 * Returns true if the size of tasks in the input stack are affected by the docked stack
748 * changing size.
749 */
Wale Ogunwale3382ab12017-07-27 08:55:03 -0700750 // TODO: What is the difference between this method and the one above??
Wale Ogunwale3797c222015-10-27 14:21:58 -0700751 public static boolean isTaskResizeableByDockedStack(int stackId) {
752 return isStaticStack(stackId) && stackId != FREEFORM_WORKSPACE_STACK_ID
Winson Chung83471632016-12-13 11:02:12 -0800753 && stackId != DOCKED_STACK_ID && stackId != PINNED_STACK_ID
754 && stackId != ASSISTANT_STACK_ID;
Wale Ogunwale3797c222015-10-27 14:21:58 -0700755 }
756
757 /**
Winson Chung2af04b32017-01-24 16:21:13 -0800758 * Returns true if the input stack is affected by drag resizing.
759 */
760 public static boolean isStackAffectedByDragResizing(int stackId) {
Winson Chung83471632016-12-13 11:02:12 -0800761 return isStaticStack(stackId) && stackId != PINNED_STACK_ID
762 && stackId != ASSISTANT_STACK_ID;
Winson Chung2af04b32017-01-24 16:21:13 -0800763 }
764
765 /**
Jorim Jaggie9098022016-01-27 19:29:40 -0800766 * Returns true if the windows of tasks being moved to the target stack from the source
767 * stack should be replaced, meaning that window manager will keep the old window around
768 * until the new is ready.
Wale Ogunwale3797c222015-10-27 14:21:58 -0700769 */
Jorim Jaggie9098022016-01-27 19:29:40 -0800770 public static boolean replaceWindowsOnTaskMove(int sourceStackId, int targetStackId) {
771 return sourceStackId == FREEFORM_WORKSPACE_STACK_ID
772 || targetStackId == FREEFORM_WORKSPACE_STACK_ID;
Wale Ogunwale3797c222015-10-27 14:21:58 -0700773 }
Filip Gruszczynski96daf322015-11-18 18:01:27 -0800774
775 /**
Winson Chung83471632016-12-13 11:02:12 -0800776 * Return whether a stackId is a stack that be a backdrop to a translucent activity. These
777 * are generally fullscreen stacks.
778 */
779 public static boolean isBackdropToTranslucentActivity(int stackId) {
780 return stackId == FULLSCREEN_WORKSPACE_STACK_ID
781 || stackId == ASSISTANT_STACK_ID;
782 }
783
784 /**
Filip Gruszczynski96daf322015-11-18 18:01:27 -0800785 * Returns true if animation specs should be constructed for app transition that moves
786 * the task to the specified stack.
787 */
788 public static boolean useAnimationSpecForAppTransition(int stackId) {
Jorim Jaggi8a5c6402016-02-12 16:55:18 -0800789 // TODO: INVALID_STACK_ID is also animated because we don't persist stack id's across
790 // reboots.
Filip Gruszczynski96daf322015-11-18 18:01:27 -0800791 return stackId == FREEFORM_WORKSPACE_STACK_ID
Winson Chung83471632016-12-13 11:02:12 -0800792 || stackId == FULLSCREEN_WORKSPACE_STACK_ID
793 || stackId == ASSISTANT_STACK_ID
794 || stackId == DOCKED_STACK_ID
Jorim Jaggi8a5c6402016-02-12 16:55:18 -0800795 || stackId == INVALID_STACK_ID;
Filip Gruszczynski96daf322015-11-18 18:01:27 -0800796 }
Wale Ogunwaled045c822015-12-02 09:14:28 -0800797
Winson Chung83471632016-12-13 11:02:12 -0800798 /**
Winson Chung83471632016-12-13 11:02:12 -0800799 * Returns true if activities from stasks in the given {@param stackId} are allowed to
800 * enter picture-in-picture.
801 */
802 public static boolean isAllowedToEnterPictureInPicture(int stackId) {
803 return stackId != HOME_STACK_ID && stackId != ASSISTANT_STACK_ID &&
804 stackId != RECENTS_STACK_ID;
Chong Zhang75b37202015-12-04 14:16:36 -0800805 }
806
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800807 /**
808 * Returns true if the top task in the task is allowed to return home when finished and
809 * there are other tasks in the stack.
810 */
811 public static boolean allowTopTaskToReturnHome(int stackId) {
812 return stackId != PINNED_STACK_ID;
813 }
Wale Ogunwalecacfaa22016-01-15 11:26:08 -0800814
815 /**
816 * Returns true if the stack should be resized to match the bounds specified by
817 * {@link ActivityOptions#setLaunchBounds} when launching an activity into the stack.
818 */
819 public static boolean resizeStackWithLaunchBounds(int stackId) {
820 return stackId == PINNED_STACK_ID;
821 }
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -0800822
823 /**
Jorim Jaggi86905582016-02-09 21:36:09 -0800824 * Returns true if a window from the specified stack with {@param stackId} are normally
825 * fullscreen, i. e. they can become the top opaque fullscreen window, meaning that it
826 * controls system bars, lockscreen occluded/dismissing state, screen rotation animation,
827 * etc.
828 */
Wale Ogunwale3382ab12017-07-27 08:55:03 -0700829 // TODO: What about the other side of docked stack if we move this to WindowConfiguration?
Jorim Jaggi86905582016-02-09 21:36:09 -0800830 public static boolean normallyFullscreenWindows(int stackId) {
831 return stackId != PINNED_STACK_ID && stackId != FREEFORM_WORKSPACE_STACK_ID
832 && stackId != DOCKED_STACK_ID;
833 }
Wale Ogunwalefb1c8642016-03-02 08:28:08 -0800834
835 /**
836 * Returns true if the input stack id should only be present on a device that supports
837 * multi-window mode.
838 * @see android.app.ActivityManager#supportsMultiWindow
839 */
Wale Ogunwale3382ab12017-07-27 08:55:03 -0700840 // TODO: What about the other side of docked stack if we move this to WindowConfiguration?
Wale Ogunwalefb1c8642016-03-02 08:28:08 -0800841 public static boolean isMultiWindowStack(int stackId) {
Winson Chung83471632016-12-13 11:02:12 -0800842 return stackId == PINNED_STACK_ID || stackId == FREEFORM_WORKSPACE_STACK_ID
843 || stackId == DOCKED_STACK_ID;
Wale Ogunwalefb1c8642016-03-02 08:28:08 -0800844 }
Wale Ogunwale43896cf2016-04-16 10:54:30 -0700845
846 /**
Matthew Ngae1ff4f2016-11-10 15:49:14 -0800847 * Returns true if the input {@param stackId} is HOME_STACK_ID or RECENTS_STACK_ID
848 */
849 public static boolean isHomeOrRecentsStack(int stackId) {
850 return stackId == HOME_STACK_ID || stackId == RECENTS_STACK_ID;
851 }
852
Wale Ogunwale51362492016-09-08 17:49:17 -0700853 /** Returns true if the input stack and its content can affect the device orientation. */
854 public static boolean canSpecifyOrientation(int stackId) {
Winson Chung83471632016-12-13 11:02:12 -0800855 return stackId == HOME_STACK_ID
856 || stackId == RECENTS_STACK_ID
857 || stackId == FULLSCREEN_WORKSPACE_STACK_ID
858 || stackId == ASSISTANT_STACK_ID
859 || isDynamicStack(stackId);
Wale Ogunwale51362492016-09-08 17:49:17 -0700860 }
Wale Ogunwalef75962a2017-08-23 14:58:04 -0700861
862 /** Returns the windowing mode that should be used for this input stack id. */
863 // TODO: To be removed once we are not using stack id for stuff...
864 public static int getWindowingModeForStackId(int stackId) {
865 final int windowingMode;
866 switch (stackId) {
867 case FULLSCREEN_WORKSPACE_STACK_ID:
868 case HOME_STACK_ID:
869 case RECENTS_STACK_ID:
870 case ASSISTANT_STACK_ID:
871 windowingMode = WINDOWING_MODE_FULLSCREEN;
872 break;
873 case PINNED_STACK_ID:
874 windowingMode = WINDOWING_MODE_PINNED;
875 break;
876 case DOCKED_STACK_ID:
877 windowingMode = WINDOWING_MODE_DOCKED;
878 break;
879 case FREEFORM_WORKSPACE_STACK_ID:
880 windowingMode = WINDOWING_MODE_FREEFORM;
881 break;
882 default :
883 windowingMode = WINDOWING_MODE_UNDEFINED;
884 }
885 return windowingMode;
886 }
Wale Ogunwale3797c222015-10-27 14:21:58 -0700887 }
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700888
Wale Ogunwale59a73ca2015-09-14 12:54:50 -0700889 /**
890 * Input parameter to {@link android.app.IActivityManager#moveTaskToDockedStack} which
891 * specifies the position of the created docked stack at the top half of the screen if
892 * in portrait mode or at the left half of the screen if in landscape mode.
893 * @hide
894 */
895 public static final int DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT = 0;
896
897 /**
898 * Input parameter to {@link android.app.IActivityManager#moveTaskToDockedStack} which
899 * specifies the position of the created docked stack at the bottom half of the screen if
900 * in portrait mode or at the right half of the screen if in landscape mode.
901 * @hide
902 */
903 public static final int DOCKED_STACK_CREATE_MODE_BOTTOM_OR_RIGHT = 1;
904
Chong Zhang87b21722015-09-21 15:39:51 -0700905 /**
906 * Input parameter to {@link android.app.IActivityManager#resizeTask} which indicates
Chong Zhang6de2ae82015-09-30 18:25:21 -0700907 * that the resize doesn't need to preserve the window, and can be skipped if bounds
908 * is unchanged. This mode is used by window manager in most cases.
Chong Zhang87b21722015-09-21 15:39:51 -0700909 * @hide
910 */
911 public static final int RESIZE_MODE_SYSTEM = 0;
912
913 /**
914 * Input parameter to {@link android.app.IActivityManager#resizeTask} which indicates
Chong Zhang6de2ae82015-09-30 18:25:21 -0700915 * that the resize should preserve the window if possible.
Wale Ogunwale1ed0d892015-09-28 13:27:44 -0700916 * @hide
917 */
Chong Zhang6de2ae82015-09-30 18:25:21 -0700918 public static final int RESIZE_MODE_PRESERVE_WINDOW = (0x1 << 0);
Chong Zhang87b21722015-09-21 15:39:51 -0700919
920 /**
921 * Input parameter to {@link android.app.IActivityManager#resizeTask} which indicates
922 * that the resize should be performed even if the bounds appears unchanged.
923 * @hide
924 */
Chong Zhang6de2ae82015-09-30 18:25:21 -0700925 public static final int RESIZE_MODE_FORCED = (0x1 << 1);
926
927 /**
928 * Input parameter to {@link android.app.IActivityManager#resizeTask} used by window
929 * manager during a screen rotation.
930 * @hide
931 */
932 public static final int RESIZE_MODE_SYSTEM_SCREEN_ROTATION = RESIZE_MODE_PRESERVE_WINDOW;
933
934 /**
935 * Input parameter to {@link android.app.IActivityManager#resizeTask} used when the
936 * resize is due to a drag action.
937 * @hide
938 */
939 public static final int RESIZE_MODE_USER = RESIZE_MODE_PRESERVE_WINDOW;
940
941 /**
942 * Input parameter to {@link android.app.IActivityManager#resizeTask} which indicates
943 * that the resize should preserve the window if possible, and should not be skipped
944 * even if the bounds is unchanged. Usually used to force a resizing when a drag action
945 * is ending.
946 * @hide
947 */
948 public static final int RESIZE_MODE_USER_FORCED =
949 RESIZE_MODE_PRESERVE_WINDOW | RESIZE_MODE_FORCED;
Chong Zhang87b21722015-09-21 15:39:51 -0700950
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700951 /** @hide */
952 public int getFrontActivityScreenCompatMode() {
953 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -0800954 return getService().getFrontActivityScreenCompatMode();
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700955 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700956 throw e.rethrowFromSystemServer();
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700957 }
958 }
959
Dianne Hackborndf9799f2011-05-12 15:16:33 -0700960 /** @hide */
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700961 public void setFrontActivityScreenCompatMode(int mode) {
962 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -0800963 getService().setFrontActivityScreenCompatMode(mode);
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700964 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700965 throw e.rethrowFromSystemServer();
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700966 }
967 }
968
Dianne Hackborndf9799f2011-05-12 15:16:33 -0700969 /** @hide */
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700970 public int getPackageScreenCompatMode(String packageName) {
971 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -0800972 return getService().getPackageScreenCompatMode(packageName);
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700973 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700974 throw e.rethrowFromSystemServer();
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700975 }
976 }
977
Dianne Hackborndf9799f2011-05-12 15:16:33 -0700978 /** @hide */
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700979 public void setPackageScreenCompatMode(String packageName, int mode) {
980 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -0800981 getService().setPackageScreenCompatMode(packageName, mode);
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700982 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700983 throw e.rethrowFromSystemServer();
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700984 }
985 }
986
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700987 /** @hide */
988 public boolean getPackageAskScreenCompat(String packageName) {
989 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -0800990 return getService().getPackageAskScreenCompat(packageName);
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700991 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700992 throw e.rethrowFromSystemServer();
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700993 }
994 }
995
996 /** @hide */
997 public void setPackageAskScreenCompat(String packageName, boolean ask) {
998 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -0800999 getService().setPackageAskScreenCompat(packageName, ask);
Dianne Hackborn36cd41f2011-05-25 21:00:46 -07001000 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001001 throw e.rethrowFromSystemServer();
Dianne Hackborn36cd41f2011-05-25 21:00:46 -07001002 }
1003 }
1004
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -07001005 /**
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -07001006 * Return the approximate per-application memory class of the current
1007 * device. This gives you an idea of how hard a memory limit you should
1008 * impose on your application to let the overall system work best. The
1009 * returned value is in megabytes; the baseline Android memory class is
1010 * 16 (which happens to be the Java heap limit of those devices); some
1011 * device with more memory may return 24 or even higher numbers.
1012 */
1013 public int getMemoryClass() {
1014 return staticGetMemoryClass();
1015 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07001016
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -07001017 /** @hide */
1018 static public int staticGetMemoryClass() {
1019 // Really brain dead right now -- just take this from the configured
1020 // vm heap size, and assume it is in megabytes and thus ends with "m".
Dianne Hackborn7ad33c82011-03-08 15:53:25 -08001021 String vmHeapSize = SystemProperties.get("dalvik.vm.heapgrowthlimit", "");
Dianne Hackbornde398512011-01-18 18:45:21 -08001022 if (vmHeapSize != null && !"".equals(vmHeapSize)) {
1023 return Integer.parseInt(vmHeapSize.substring(0, vmHeapSize.length()-1));
1024 }
1025 return staticGetLargeMemoryClass();
Dianne Hackborn4e24aac2010-12-23 11:43:46 -08001026 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07001027
Dianne Hackborn4e24aac2010-12-23 11:43:46 -08001028 /**
1029 * Return the approximate per-application memory class of the current
1030 * device when an application is running with a large heap. This is the
1031 * space available for memory-intensive applications; most applications
1032 * should not need this amount of memory, and should instead stay with the
1033 * {@link #getMemoryClass()} limit. The returned value is in megabytes.
1034 * This may be the same size as {@link #getMemoryClass()} on memory
1035 * constrained devices, or it may be significantly larger on devices with
1036 * a large amount of available RAM.
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08001037 *
1038 * <p>The is the size of the application's Dalvik heap if it has
1039 * specified <code>android:largeHeap="true"</code> in its manifest.
Dianne Hackborn4e24aac2010-12-23 11:43:46 -08001040 */
1041 public int getLargeMemoryClass() {
1042 return staticGetLargeMemoryClass();
1043 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07001044
Dianne Hackborn4e24aac2010-12-23 11:43:46 -08001045 /** @hide */
1046 static public int staticGetLargeMemoryClass() {
1047 // Really brain dead right now -- just take this from the configured
1048 // vm heap size, and assume it is in megabytes and thus ends with "m".
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -07001049 String vmHeapSize = SystemProperties.get("dalvik.vm.heapsize", "16m");
Dianne Hackborn852975d2014-08-22 17:42:43 -07001050 return Integer.parseInt(vmHeapSize.substring(0, vmHeapSize.length() - 1));
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -07001051 }
Dianne Hackbornb4e12492013-06-26 15:08:19 -07001052
1053 /**
1054 * Returns true if this is a low-RAM device. Exactly whether a device is low-RAM
1055 * is ultimately up to the device configuration, but currently it generally means
1056 * something in the class of a 512MB device with about a 800x480 or less screen.
1057 * This is mostly intended to be used by apps to determine whether they should turn
1058 * off certain features that require more RAM.
1059 */
1060 public boolean isLowRamDevice() {
1061 return isLowRamDeviceStatic();
1062 }
1063
1064 /** @hide */
1065 public static boolean isLowRamDeviceStatic() {
Marc Hittinger17fb5962017-04-05 15:34:38 -07001066 return RoSystemProperties.CONFIG_LOW_RAM ||
1067 (Build.IS_DEBUGGABLE && DEVELOPMENT_FORCE_LOW_RAM);
Dianne Hackbornb4e12492013-06-26 15:08:19 -07001068 }
1069
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -07001070 /**
Michael Kwan15eb9982017-04-14 12:34:46 -07001071 * Returns true if this is a small battery device. Exactly whether a device is considered to be
1072 * small battery is ultimately up to the device configuration, but currently it generally means
1073 * something in the class of a device with 1000 mAh or less. This is mostly intended to be used
1074 * to determine whether certain features should be altered to account for a drastically smaller
1075 * battery.
1076 * @hide
1077 */
1078 public static boolean isSmallBatteryDevice() {
1079 return RoSystemProperties.CONFIG_SMALL_BATTERY;
1080 }
1081
1082 /**
Dianne Hackbornb3756322011-08-12 13:58:13 -07001083 * Used by persistent processes to determine if they are running on a
1084 * higher-end device so should be okay using hardware drawing acceleration
1085 * (which tends to consume a lot more RAM).
1086 * @hide
1087 */
Jeff Brown98365d72012-08-19 20:30:52 -07001088 static public boolean isHighEndGfx() {
Dianne Hackbornb4e12492013-06-26 15:08:19 -07001089 return !isLowRamDeviceStatic() &&
1090 !Resources.getSystem().getBoolean(com.android.internal.R.bool.config_avoidGfxAccel);
Dianne Hackborn49d228b32011-08-24 17:37:31 -07001091 }
1092
1093 /**
Dianne Hackborn852975d2014-08-22 17:42:43 -07001094 * Return the maximum number of recents entries that we will maintain and show.
1095 * @hide
1096 */
1097 static public int getMaxRecentTasksStatic() {
1098 if (gMaxRecentTasks < 0) {
Winson7c402912016-05-10 13:59:36 -07001099 return gMaxRecentTasks = isLowRamDeviceStatic() ? 36 : 48;
Dianne Hackborn852975d2014-08-22 17:42:43 -07001100 }
1101 return gMaxRecentTasks;
1102 }
1103
1104 /**
1105 * Return the default limit on the number of recents that an app can make.
1106 * @hide
1107 */
1108 static public int getDefaultAppRecentsLimitStatic() {
1109 return getMaxRecentTasksStatic() / 6;
1110 }
1111
1112 /**
1113 * Return the maximum limit on the number of recents that an app can make.
1114 * @hide
1115 */
1116 static public int getMaxAppRecentsLimitStatic() {
1117 return getMaxRecentTasksStatic() / 2;
1118 }
1119
1120 /**
Wale Ogunwalefb1c8642016-03-02 08:28:08 -08001121 * Returns true if the system supports at least one form of multi-window.
1122 * E.g. freeform, split-screen, picture-in-picture.
1123 * @hide
1124 */
Erik Wolsheimer9be3a062017-05-31 14:59:57 -07001125 static public boolean supportsMultiWindow(Context context) {
1126 // On watches, multi-window is used to present essential system UI, and thus it must be
1127 // supported regardless of device memory characteristics.
1128 boolean isWatch = context.getPackageManager().hasSystemFeature(
1129 PackageManager.FEATURE_WATCH);
1130 return (!isLowRamDeviceStatic() || isWatch)
Wale Ogunwalefb1c8642016-03-02 08:28:08 -08001131 && Resources.getSystem().getBoolean(
1132 com.android.internal.R.bool.config_supportsMultiWindow);
1133 }
1134
1135 /**
Matthew Ng626e0cc2016-12-07 17:25:53 -08001136 * Returns true if the system supports split screen multi-window.
1137 * @hide
1138 */
Erik Wolsheimer9be3a062017-05-31 14:59:57 -07001139 static public boolean supportsSplitScreenMultiWindow(Context context) {
1140 return supportsMultiWindow(context)
Matthew Ng626e0cc2016-12-07 17:25:53 -08001141 && Resources.getSystem().getBoolean(
1142 com.android.internal.R.bool.config_supportsSplitScreenMultiWindow);
1143 }
1144
Jeff Sharkey000ce802017-04-29 13:13:27 -06001145 /** @removed */
Winson Chung709904f2017-04-25 11:00:48 -07001146 @Deprecated
Winson Chunga29eb982016-12-14 12:01:27 -08001147 public static int getMaxNumPictureInPictureActions() {
Winson Chung709904f2017-04-25 11:00:48 -07001148 return 3;
Winson Chunga29eb982016-12-14 12:01:27 -08001149 }
1150
1151 /**
Winson Chung1147c402014-05-14 11:05:00 -07001152 * Information you can set and retrieve about the current activity within the recent task list.
Winson Chung03a9bae2014-05-02 09:56:12 -07001153 */
Winson Chunga449dc02014-05-16 11:15:04 -07001154 public static class TaskDescription implements Parcelable {
Craig Mautner648f69b2014-09-18 14:16:26 -07001155 /** @hide */
1156 public static final String ATTR_TASKDESCRIPTION_PREFIX = "task_description_";
1157 private static final String ATTR_TASKDESCRIPTIONLABEL =
1158 ATTR_TASKDESCRIPTION_PREFIX + "label";
Winson Chung1af8eda2016-02-05 17:55:56 +00001159 private static final String ATTR_TASKDESCRIPTIONCOLOR_PRIMARY =
Craig Mautner648f69b2014-09-18 14:16:26 -07001160 ATTR_TASKDESCRIPTION_PREFIX + "color";
Winson Chung1af8eda2016-02-05 17:55:56 +00001161 private static final String ATTR_TASKDESCRIPTIONCOLOR_BACKGROUND =
1162 ATTR_TASKDESCRIPTION_PREFIX + "colorBackground";
Craig Mautner648f69b2014-09-18 14:16:26 -07001163 private static final String ATTR_TASKDESCRIPTIONICONFILENAME =
1164 ATTR_TASKDESCRIPTION_PREFIX + "icon_filename";
1165
Winson Chunga449dc02014-05-16 11:15:04 -07001166 private String mLabel;
1167 private Bitmap mIcon;
Craig Mautner648f69b2014-09-18 14:16:26 -07001168 private String mIconFilename;
Winson Chunga449dc02014-05-16 11:15:04 -07001169 private int mColorPrimary;
Winson Chung1af8eda2016-02-05 17:55:56 +00001170 private int mColorBackground;
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001171 private int mStatusBarColor;
1172 private int mNavigationBarColor;
Winson Chung03a9bae2014-05-02 09:56:12 -07001173
1174 /**
Winson Chunga449dc02014-05-16 11:15:04 -07001175 * Creates the TaskDescription to the specified values.
Winson Chung03a9bae2014-05-02 09:56:12 -07001176 *
Winson Chunga449dc02014-05-16 11:15:04 -07001177 * @param label A label and description of the current state of this task.
1178 * @param icon An icon that represents the current state of this task.
Winson Chung1af8eda2016-02-05 17:55:56 +00001179 * @param colorPrimary A color to override the theme's primary color. This color must be
1180 * opaque.
Winson Chung03a9bae2014-05-02 09:56:12 -07001181 */
Winson Chunga449dc02014-05-16 11:15:04 -07001182 public TaskDescription(String label, Bitmap icon, int colorPrimary) {
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001183 this(label, icon, null, colorPrimary, 0, 0, 0);
Winson Chunga449dc02014-05-16 11:15:04 -07001184 if ((colorPrimary != 0) && (Color.alpha(colorPrimary) != 255)) {
1185 throw new RuntimeException("A TaskDescription's primary color should be opaque");
1186 }
Craig Mautner648f69b2014-09-18 14:16:26 -07001187 }
1188
Winson Chung03a9bae2014-05-02 09:56:12 -07001189 /**
Winson Chunga449dc02014-05-16 11:15:04 -07001190 * Creates the TaskDescription to the specified values.
Winson Chung03a9bae2014-05-02 09:56:12 -07001191 *
1192 * @param label A label and description of the current state of this activity.
1193 * @param icon An icon that represents the current state of this activity.
1194 */
Winson Chunga449dc02014-05-16 11:15:04 -07001195 public TaskDescription(String label, Bitmap icon) {
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001196 this(label, icon, null, 0, 0, 0, 0);
Winson Chung03a9bae2014-05-02 09:56:12 -07001197 }
1198
1199 /**
Winson Chunga449dc02014-05-16 11:15:04 -07001200 * Creates the TaskDescription to the specified values.
Winson Chung03a9bae2014-05-02 09:56:12 -07001201 *
1202 * @param label A label and description of the current state of this activity.
1203 */
Winson Chunga449dc02014-05-16 11:15:04 -07001204 public TaskDescription(String label) {
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001205 this(label, null, null, 0, 0, 0, 0);
Winson Chung03a9bae2014-05-02 09:56:12 -07001206 }
1207
Winson Chunga449dc02014-05-16 11:15:04 -07001208 /**
1209 * Creates an empty TaskDescription.
1210 */
1211 public TaskDescription() {
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001212 this(null, null, null, 0, 0, 0, 0);
Winson Chung1af8eda2016-02-05 17:55:56 +00001213 }
1214
1215 /** @hide */
1216 public TaskDescription(String label, Bitmap icon, String iconFilename, int colorPrimary,
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001217 int colorBackground, int statusBarColor, int navigationBarColor) {
Winson Chung1af8eda2016-02-05 17:55:56 +00001218 mLabel = label;
1219 mIcon = icon;
1220 mIconFilename = iconFilename;
1221 mColorPrimary = colorPrimary;
1222 mColorBackground = colorBackground;
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001223 mStatusBarColor = statusBarColor;
1224 mNavigationBarColor = navigationBarColor;
Winson Chung03a9bae2014-05-02 09:56:12 -07001225 }
1226
Winson Chunga449dc02014-05-16 11:15:04 -07001227 /**
1228 * Creates a copy of another TaskDescription.
1229 */
1230 public TaskDescription(TaskDescription td) {
Winsonb6403152016-02-23 13:32:09 -08001231 copyFrom(td);
1232 }
1233
1234 /**
1235 * Copies this the values from another TaskDescription.
1236 * @hide
1237 */
1238 public void copyFrom(TaskDescription other) {
1239 mLabel = other.mLabel;
1240 mIcon = other.mIcon;
1241 mIconFilename = other.mIconFilename;
1242 mColorPrimary = other.mColorPrimary;
1243 mColorBackground = other.mColorBackground;
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001244 mStatusBarColor = other.mStatusBarColor;
1245 mNavigationBarColor = other.mNavigationBarColor;
Winson Chunga449dc02014-05-16 11:15:04 -07001246 }
1247
Jorim Jaggif4156ea2017-04-10 18:39:04 -07001248 /**
1249 * Copies this the values from another TaskDescription, but preserves the hidden fields
1250 * if they weren't set on {@code other}
1251 * @hide
1252 */
1253 public void copyFromPreserveHiddenFields(TaskDescription other) {
1254 mLabel = other.mLabel;
1255 mIcon = other.mIcon;
1256 mIconFilename = other.mIconFilename;
1257 mColorPrimary = other.mColorPrimary;
1258 if (other.mColorBackground != 0) {
1259 mColorBackground = other.mColorBackground;
1260 }
1261 if (other.mStatusBarColor != 0) {
1262 mStatusBarColor = other.mStatusBarColor;
1263 }
1264 if (other.mNavigationBarColor != 0) {
1265 mNavigationBarColor = other.mNavigationBarColor;
1266 }
1267 }
1268
Winson Chunga449dc02014-05-16 11:15:04 -07001269 private TaskDescription(Parcel source) {
Winson Chung03a9bae2014-05-02 09:56:12 -07001270 readFromParcel(source);
1271 }
1272
1273 /**
Winson Chung2cb86c72014-06-25 12:03:30 -07001274 * Sets the label for this task description.
1275 * @hide
1276 */
1277 public void setLabel(String label) {
1278 mLabel = label;
1279 }
1280
1281 /**
1282 * Sets the primary color for this task description.
1283 * @hide
1284 */
1285 public void setPrimaryColor(int primaryColor) {
Winson Chungae12dae2014-09-29 14:21:26 -07001286 // Ensure that the given color is valid
1287 if ((primaryColor != 0) && (Color.alpha(primaryColor) != 255)) {
1288 throw new RuntimeException("A TaskDescription's primary color should be opaque");
1289 }
1290 mColorPrimary = primaryColor;
Winson Chung2cb86c72014-06-25 12:03:30 -07001291 }
1292
1293 /**
Winson Chung1af8eda2016-02-05 17:55:56 +00001294 * Sets the background color for this task description.
1295 * @hide
1296 */
1297 public void setBackgroundColor(int backgroundColor) {
1298 // Ensure that the given color is valid
1299 if ((backgroundColor != 0) && (Color.alpha(backgroundColor) != 255)) {
1300 throw new RuntimeException("A TaskDescription's background color should be opaque");
1301 }
1302 mColorBackground = backgroundColor;
1303 }
1304
1305 /**
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001306 * @hide
1307 */
1308 public void setStatusBarColor(int statusBarColor) {
1309 mStatusBarColor = statusBarColor;
1310 }
1311
1312 /**
1313 * @hide
1314 */
1315 public void setNavigationBarColor(int navigationBarColor) {
1316 mNavigationBarColor = navigationBarColor;
1317 }
1318
1319 /**
Winson Chung2cb86c72014-06-25 12:03:30 -07001320 * Sets the icon for this task description.
1321 * @hide
1322 */
1323 public void setIcon(Bitmap icon) {
1324 mIcon = icon;
1325 }
1326
1327 /**
Craig Mautner648f69b2014-09-18 14:16:26 -07001328 * Moves the icon bitmap reference from an actual Bitmap to a file containing the
1329 * bitmap.
1330 * @hide
1331 */
1332 public void setIconFilename(String iconFilename) {
1333 mIconFilename = iconFilename;
1334 mIcon = null;
1335 }
1336
1337 /**
Winson Chunga449dc02014-05-16 11:15:04 -07001338 * @return The label and description of the current state of this task.
Winson Chung03a9bae2014-05-02 09:56:12 -07001339 */
Winson Chunga449dc02014-05-16 11:15:04 -07001340 public String getLabel() {
1341 return mLabel;
1342 }
1343
1344 /**
1345 * @return The icon that represents the current state of this task.
1346 */
1347 public Bitmap getIcon() {
Craig Mautner648f69b2014-09-18 14:16:26 -07001348 if (mIcon != null) {
1349 return mIcon;
1350 }
Suprabh Shukla23593142015-11-03 17:31:15 -08001351 return loadTaskDescriptionIcon(mIconFilename, UserHandle.myUserId());
Craig Mautner648f69b2014-09-18 14:16:26 -07001352 }
1353
1354 /** @hide */
1355 public String getIconFilename() {
1356 return mIconFilename;
Winson Chunga449dc02014-05-16 11:15:04 -07001357 }
1358
Jorim Jaggibdd4b202014-09-26 18:29:07 +02001359 /** @hide */
1360 public Bitmap getInMemoryIcon() {
1361 return mIcon;
1362 }
1363
1364 /** @hide */
Suprabh Shukla23593142015-11-03 17:31:15 -08001365 public static Bitmap loadTaskDescriptionIcon(String iconFilename, int userId) {
Jorim Jaggibdd4b202014-09-26 18:29:07 +02001366 if (iconFilename != null) {
1367 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001368 return getService().getTaskDescriptionIcon(iconFilename,
Winson Chung1af8eda2016-02-05 17:55:56 +00001369 userId);
Jorim Jaggibdd4b202014-09-26 18:29:07 +02001370 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001371 throw e.rethrowFromSystemServer();
Jorim Jaggibdd4b202014-09-26 18:29:07 +02001372 }
1373 }
1374 return null;
1375 }
1376
Winson Chunga449dc02014-05-16 11:15:04 -07001377 /**
1378 * @return The color override on the theme's primary color.
1379 */
1380 public int getPrimaryColor() {
1381 return mColorPrimary;
Winson Chung03a9bae2014-05-02 09:56:12 -07001382 }
1383
Winson Chung1af8eda2016-02-05 17:55:56 +00001384 /**
1385 * @return The background color.
1386 * @hide
1387 */
1388 public int getBackgroundColor() {
1389 return mColorBackground;
1390 }
1391
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001392 /**
1393 * @hide
1394 */
1395 public int getStatusBarColor() {
1396 return mStatusBarColor;
1397 }
1398
1399 /**
1400 * @hide
1401 */
1402 public int getNavigationBarColor() {
1403 return mNavigationBarColor;
1404 }
1405
Craig Mautner648f69b2014-09-18 14:16:26 -07001406 /** @hide */
1407 public void saveToXml(XmlSerializer out) throws IOException {
1408 if (mLabel != null) {
1409 out.attribute(null, ATTR_TASKDESCRIPTIONLABEL, mLabel);
1410 }
1411 if (mColorPrimary != 0) {
Winson Chung1af8eda2016-02-05 17:55:56 +00001412 out.attribute(null, ATTR_TASKDESCRIPTIONCOLOR_PRIMARY,
1413 Integer.toHexString(mColorPrimary));
1414 }
1415 if (mColorBackground != 0) {
1416 out.attribute(null, ATTR_TASKDESCRIPTIONCOLOR_BACKGROUND,
1417 Integer.toHexString(mColorBackground));
Craig Mautner648f69b2014-09-18 14:16:26 -07001418 }
1419 if (mIconFilename != null) {
1420 out.attribute(null, ATTR_TASKDESCRIPTIONICONFILENAME, mIconFilename);
1421 }
1422 }
1423
1424 /** @hide */
1425 public void restoreFromXml(String attrName, String attrValue) {
1426 if (ATTR_TASKDESCRIPTIONLABEL.equals(attrName)) {
1427 setLabel(attrValue);
Winson Chung1af8eda2016-02-05 17:55:56 +00001428 } else if (ATTR_TASKDESCRIPTIONCOLOR_PRIMARY.equals(attrName)) {
Craig Mautner648f69b2014-09-18 14:16:26 -07001429 setPrimaryColor((int) Long.parseLong(attrValue, 16));
Winson Chung1af8eda2016-02-05 17:55:56 +00001430 } else if (ATTR_TASKDESCRIPTIONCOLOR_BACKGROUND.equals(attrName)) {
1431 setBackgroundColor((int) Long.parseLong(attrValue, 16));
Craig Mautner648f69b2014-09-18 14:16:26 -07001432 } else if (ATTR_TASKDESCRIPTIONICONFILENAME.equals(attrName)) {
1433 setIconFilename(attrValue);
1434 }
1435 }
1436
Winson Chung03a9bae2014-05-02 09:56:12 -07001437 @Override
1438 public int describeContents() {
1439 return 0;
1440 }
1441
1442 @Override
1443 public void writeToParcel(Parcel dest, int flags) {
Winson Chunga449dc02014-05-16 11:15:04 -07001444 if (mLabel == null) {
Winson Chung03a9bae2014-05-02 09:56:12 -07001445 dest.writeInt(0);
1446 } else {
1447 dest.writeInt(1);
Winson Chunga449dc02014-05-16 11:15:04 -07001448 dest.writeString(mLabel);
Winson Chung03a9bae2014-05-02 09:56:12 -07001449 }
Winson Chunga449dc02014-05-16 11:15:04 -07001450 if (mIcon == null) {
1451 dest.writeInt(0);
1452 } else {
1453 dest.writeInt(1);
1454 mIcon.writeToParcel(dest, 0);
1455 }
1456 dest.writeInt(mColorPrimary);
Winson Chung1af8eda2016-02-05 17:55:56 +00001457 dest.writeInt(mColorBackground);
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001458 dest.writeInt(mStatusBarColor);
1459 dest.writeInt(mNavigationBarColor);
Craig Mautner648f69b2014-09-18 14:16:26 -07001460 if (mIconFilename == null) {
1461 dest.writeInt(0);
1462 } else {
1463 dest.writeInt(1);
1464 dest.writeString(mIconFilename);
1465 }
Winson Chung03a9bae2014-05-02 09:56:12 -07001466 }
1467
1468 public void readFromParcel(Parcel source) {
Winson Chunga449dc02014-05-16 11:15:04 -07001469 mLabel = source.readInt() > 0 ? source.readString() : null;
1470 mIcon = source.readInt() > 0 ? Bitmap.CREATOR.createFromParcel(source) : null;
1471 mColorPrimary = source.readInt();
Winson Chung1af8eda2016-02-05 17:55:56 +00001472 mColorBackground = source.readInt();
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001473 mStatusBarColor = source.readInt();
1474 mNavigationBarColor = source.readInt();
Craig Mautner648f69b2014-09-18 14:16:26 -07001475 mIconFilename = source.readInt() > 0 ? source.readString() : null;
Winson Chung03a9bae2014-05-02 09:56:12 -07001476 }
1477
Winson Chunga449dc02014-05-16 11:15:04 -07001478 public static final Creator<TaskDescription> CREATOR
1479 = new Creator<TaskDescription>() {
1480 public TaskDescription createFromParcel(Parcel source) {
1481 return new TaskDescription(source);
Winson Chung03a9bae2014-05-02 09:56:12 -07001482 }
Winson Chunga449dc02014-05-16 11:15:04 -07001483 public TaskDescription[] newArray(int size) {
1484 return new TaskDescription[size];
Winson Chung03a9bae2014-05-02 09:56:12 -07001485 }
1486 };
1487
1488 @Override
1489 public String toString() {
Winson Chunga449dc02014-05-16 11:15:04 -07001490 return "TaskDescription Label: " + mLabel + " Icon: " + mIcon +
Winson Chung1af8eda2016-02-05 17:55:56 +00001491 " IconFilename: " + mIconFilename + " colorPrimary: " + mColorPrimary +
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001492 " colorBackground: " + mColorBackground +
1493 " statusBarColor: " + mColorBackground +
1494 " navigationBarColor: " + mNavigationBarColor;
Winson Chung03a9bae2014-05-02 09:56:12 -07001495 }
1496 }
1497
1498 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001499 * Information you can retrieve about tasks that the user has most recently
1500 * started or visited.
1501 */
1502 public static class RecentTaskInfo implements Parcelable {
1503 /**
1504 * If this task is currently running, this is the identifier for it.
1505 * If it is not running, this will be -1.
1506 */
1507 public int id;
1508
1509 /**
Dianne Hackbornd94df452011-02-16 18:53:31 -08001510 * The true identifier of this task, valid even if it is not running.
1511 */
1512 public int persistentId;
Stefan Kuhne16045c22015-06-05 07:18:06 -07001513
Dianne Hackbornd94df452011-02-16 18:53:31 -08001514 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001515 * The original Intent used to launch the task. You can use this
1516 * Intent to re-launch the task (if it is no longer running) or bring
1517 * the current task to the front.
1518 */
1519 public Intent baseIntent;
1520
1521 /**
1522 * If this task was started from an alias, this is the actual
1523 * activity component that was initially started; the component of
1524 * the baseIntent in this case is the name of the actual activity
1525 * implementation that the alias referred to. Otherwise, this is null.
1526 */
1527 public ComponentName origActivity;
Dianne Hackbornd2835932010-12-13 16:28:46 -08001528
1529 /**
James Cook4d0ef042015-07-09 14:28:23 -07001530 * The actual activity component that started the task.
1531 * @hide
1532 */
1533 @Nullable
1534 public ComponentName realActivity;
1535
1536 /**
Dianne Hackbornd2835932010-12-13 16:28:46 -08001537 * Description of the task's last state.
1538 */
1539 public CharSequence description;
Craig Mautner6d90fed2013-05-22 15:03:10 -07001540
1541 /**
1542 * The id of the ActivityStack this Task was on most recently.
Craig Mautner27030522013-08-26 12:25:36 -07001543 * @hide
Craig Mautner6d90fed2013-05-22 15:03:10 -07001544 */
1545 public int stackId;
1546
Kenny Guy82326a92014-03-17 17:16:06 +00001547 /**
Craig Mautner2fbd7542014-03-21 09:34:07 -07001548 * The id of the user the task was running as.
Kenny Guy82326a92014-03-17 17:16:06 +00001549 * @hide
1550 */
1551 public int userId;
1552
Craig Mautner2fbd7542014-03-21 09:34:07 -07001553 /**
Winson Chungffa2ec62014-07-03 15:54:42 -07001554 * The first time this task was active.
1555 * @hide
1556 */
1557 public long firstActiveTime;
1558
1559 /**
Winson Chungf1fbd772014-06-24 18:06:58 -07001560 * The last time this task was active.
1561 * @hide
1562 */
1563 public long lastActiveTime;
1564
1565 /**
Winson Chung03a9bae2014-05-02 09:56:12 -07001566 * The recent activity values for the highest activity in the stack to have set the values.
Winson Chunga449dc02014-05-16 11:15:04 -07001567 * {@link Activity#setTaskDescription(android.app.ActivityManager.TaskDescription)}.
Craig Mautner2fbd7542014-03-21 09:34:07 -07001568 */
Winson Chunga449dc02014-05-16 11:15:04 -07001569 public TaskDescription taskDescription;
Craig Mautner2fbd7542014-03-21 09:34:07 -07001570
Craig Mautnera228ae92014-07-09 05:44:55 -07001571 /**
1572 * Task affiliation for grouping with other tasks.
Craig Mautnera228ae92014-07-09 05:44:55 -07001573 */
1574 public int affiliatedTaskId;
1575
Winson Chungec396d62014-08-06 17:08:00 -07001576 /**
1577 * Task affiliation color of the source task with the affiliated task id.
1578 *
1579 * @hide
1580 */
1581 public int affiliatedTaskColor;
1582
Wale Ogunwale6035e012015-04-14 15:54:10 -07001583 /**
1584 * The component launched as the first activity in the task.
1585 * This can be considered the "application" of this task.
1586 */
1587 public ComponentName baseActivity;
1588
1589 /**
1590 * The activity component at the top of the history stack of the task.
1591 * This is what the user is currently doing.
1592 */
1593 public ComponentName topActivity;
1594
1595 /**
1596 * Number of activities in this task.
1597 */
1598 public int numActivities;
1599
Winson2dd76942015-11-02 09:20:01 -08001600 /**
1601 * The bounds of the task.
1602 * @hide
1603 */
1604 public Rect bounds;
1605
Wale Ogunwale21b60582016-01-27 12:34:16 -08001606 /**
1607 * True if the task can go in the docked stack.
1608 * @hide
1609 */
Winson Chungd3395382016-12-13 11:49:09 -08001610 public boolean supportsSplitScreenMultiWindow;
Wale Ogunwale21b60582016-01-27 12:34:16 -08001611
Jorim Jaggi29379ec2016-04-11 23:43:42 -07001612 /**
1613 * The resize mode of the task. See {@link ActivityInfo#resizeMode}.
1614 * @hide
1615 */
1616 public int resizeMode;
1617
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001618 public RecentTaskInfo() {
1619 }
1620
Craig Mautner6d90fed2013-05-22 15:03:10 -07001621 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001622 public int describeContents() {
1623 return 0;
1624 }
1625
Craig Mautner6d90fed2013-05-22 15:03:10 -07001626 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001627 public void writeToParcel(Parcel dest, int flags) {
1628 dest.writeInt(id);
Dianne Hackbornd94df452011-02-16 18:53:31 -08001629 dest.writeInt(persistentId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001630 if (baseIntent != null) {
1631 dest.writeInt(1);
1632 baseIntent.writeToParcel(dest, 0);
1633 } else {
1634 dest.writeInt(0);
1635 }
1636 ComponentName.writeToParcel(origActivity, dest);
James Cook4d0ef042015-07-09 14:28:23 -07001637 ComponentName.writeToParcel(realActivity, dest);
Dianne Hackbornd2835932010-12-13 16:28:46 -08001638 TextUtils.writeToParcel(description, dest,
1639 Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
Winson Chunga449dc02014-05-16 11:15:04 -07001640 if (taskDescription != null) {
Craig Mautner2fbd7542014-03-21 09:34:07 -07001641 dest.writeInt(1);
Winson Chunga449dc02014-05-16 11:15:04 -07001642 taskDescription.writeToParcel(dest, 0);
Winson Chung03a9bae2014-05-02 09:56:12 -07001643 } else {
1644 dest.writeInt(0);
Craig Mautner2fbd7542014-03-21 09:34:07 -07001645 }
Craig Mautner6d90fed2013-05-22 15:03:10 -07001646 dest.writeInt(stackId);
Kenny Guy82326a92014-03-17 17:16:06 +00001647 dest.writeInt(userId);
Winson Chungffa2ec62014-07-03 15:54:42 -07001648 dest.writeLong(firstActiveTime);
Winson Chungf1fbd772014-06-24 18:06:58 -07001649 dest.writeLong(lastActiveTime);
Craig Mautnera228ae92014-07-09 05:44:55 -07001650 dest.writeInt(affiliatedTaskId);
Winson Chungec396d62014-08-06 17:08:00 -07001651 dest.writeInt(affiliatedTaskColor);
Wale Ogunwale6035e012015-04-14 15:54:10 -07001652 ComponentName.writeToParcel(baseActivity, dest);
1653 ComponentName.writeToParcel(topActivity, dest);
1654 dest.writeInt(numActivities);
Winson2dd76942015-11-02 09:20:01 -08001655 if (bounds != null) {
1656 dest.writeInt(1);
1657 bounds.writeToParcel(dest, 0);
1658 } else {
1659 dest.writeInt(0);
1660 }
Winson Chungd3395382016-12-13 11:49:09 -08001661 dest.writeInt(supportsSplitScreenMultiWindow ? 1 : 0);
Jorim Jaggi29379ec2016-04-11 23:43:42 -07001662 dest.writeInt(resizeMode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001663 }
1664
1665 public void readFromParcel(Parcel source) {
1666 id = source.readInt();
Dianne Hackbornd94df452011-02-16 18:53:31 -08001667 persistentId = source.readInt();
Craig Mautner688b5102014-03-27 16:55:03 -07001668 baseIntent = source.readInt() > 0 ? Intent.CREATOR.createFromParcel(source) : null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001669 origActivity = ComponentName.readFromParcel(source);
James Cook4d0ef042015-07-09 14:28:23 -07001670 realActivity = ComponentName.readFromParcel(source);
Dianne Hackbornd2835932010-12-13 16:28:46 -08001671 description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
Winson Chunga449dc02014-05-16 11:15:04 -07001672 taskDescription = source.readInt() > 0 ?
1673 TaskDescription.CREATOR.createFromParcel(source) : null;
Craig Mautner6d90fed2013-05-22 15:03:10 -07001674 stackId = source.readInt();
Kenny Guy82326a92014-03-17 17:16:06 +00001675 userId = source.readInt();
Winson Chungffa2ec62014-07-03 15:54:42 -07001676 firstActiveTime = source.readLong();
Winson Chungf1fbd772014-06-24 18:06:58 -07001677 lastActiveTime = source.readLong();
Craig Mautnera228ae92014-07-09 05:44:55 -07001678 affiliatedTaskId = source.readInt();
Winson Chungec396d62014-08-06 17:08:00 -07001679 affiliatedTaskColor = source.readInt();
Wale Ogunwale6035e012015-04-14 15:54:10 -07001680 baseActivity = ComponentName.readFromParcel(source);
1681 topActivity = ComponentName.readFromParcel(source);
1682 numActivities = source.readInt();
Winson2dd76942015-11-02 09:20:01 -08001683 bounds = source.readInt() > 0 ?
1684 Rect.CREATOR.createFromParcel(source) : null;
Winson Chungd3395382016-12-13 11:49:09 -08001685 supportsSplitScreenMultiWindow = source.readInt() == 1;
Jorim Jaggi29379ec2016-04-11 23:43:42 -07001686 resizeMode = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001687 }
Craig Mautner6d90fed2013-05-22 15:03:10 -07001688
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001689 public static final Creator<RecentTaskInfo> CREATOR
1690 = new Creator<RecentTaskInfo>() {
1691 public RecentTaskInfo createFromParcel(Parcel source) {
1692 return new RecentTaskInfo(source);
1693 }
1694 public RecentTaskInfo[] newArray(int size) {
1695 return new RecentTaskInfo[size];
1696 }
1697 };
1698
1699 private RecentTaskInfo(Parcel source) {
1700 readFromParcel(source);
1701 }
1702 }
1703
1704 /**
1705 * Flag for use with {@link #getRecentTasks}: return all tasks, even those
1706 * that have set their
1707 * {@link android.content.Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} flag.
1708 */
1709 public static final int RECENT_WITH_EXCLUDED = 0x0001;
Kenny Guy82326a92014-03-17 17:16:06 +00001710
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001711 /**
Dianne Hackbornd2835932010-12-13 16:28:46 -08001712 * Provides a list that does not contain any
Dianne Hackborn53d9264d2010-04-13 12:49:14 -07001713 * recent tasks that currently are not available to the user.
1714 */
1715 public static final int RECENT_IGNORE_UNAVAILABLE = 0x0002;
Dianne Hackbornd2835932010-12-13 16:28:46 -08001716
1717 /**
Kenny Guy2a764942014-04-02 13:29:20 +01001718 * Provides a list that contains recent tasks for all
1719 * profiles of a user.
Kenny Guy82326a92014-03-17 17:16:06 +00001720 * @hide
1721 */
Kenny Guy2a764942014-04-02 13:29:20 +01001722 public static final int RECENT_INCLUDE_PROFILES = 0x0004;
Kenny Guy82326a92014-03-17 17:16:06 +00001723
1724 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001725 * Ignores all tasks that are on the home stack.
1726 * @hide
1727 */
Matthew Ngae1ff4f2016-11-10 15:49:14 -08001728 public static final int RECENT_IGNORE_HOME_AND_RECENTS_STACK_TASKS = 0x0008;
Winson Chunga4ccb862014-08-22 15:26:27 -07001729
1730 /**
Wale Ogunwale64ae08a2016-03-28 08:15:27 -07001731 * Ignores the top task in the docked stack.
Winson Chung0583d3d2015-12-18 10:03:12 -05001732 * @hide
1733 */
Wale Ogunwale64ae08a2016-03-28 08:15:27 -07001734 public static final int RECENT_INGORE_DOCKED_STACK_TOP_TASK = 0x0010;
Winson Chung0583d3d2015-12-18 10:03:12 -05001735
1736 /**
1737 * Ignores all tasks that are on the pinned stack.
1738 * @hide
1739 */
1740 public static final int RECENT_INGORE_PINNED_STACK_TASKS = 0x0020;
1741
1742 /**
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001743 * <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 -08001744 * the most recent being first and older ones after in order.
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07001745 *
1746 * <p><b>Note: this method is only intended for debugging and presenting
1747 * task management user interfaces</b>. This should never be used for
1748 * core logic in an application, such as deciding between different
1749 * behaviors based on the information found here. Such uses are
1750 * <em>not</em> supported, and will likely break in the future. For
1751 * example, if multiple applications can be actively running at the
1752 * same time, assumptions made about the meaning of the data here for
1753 * purposes of control flow will be incorrect.</p>
1754 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07001755 * @deprecated As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method is
Dianne Hackborn2d7576b2014-10-03 16:26:04 -07001756 * no longer available to third party applications: the introduction of
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001757 * document-centric recents means
1758 * it can leak personal information to the caller. For backwards compatibility,
1759 * it will still return a small subset of its data: at least the caller's
1760 * own tasks (though see {@link #getAppTasks()} for the correct supported
1761 * way to retrieve that information), and possibly some other tasks
1762 * such as home that are known to not be sensitive.
1763 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001764 * @param maxNum The maximum number of entries to return in the list. The
1765 * actual number returned may be smaller, depending on how many tasks the
1766 * user has started and the maximum number the system can remember.
Dianne Hackbornd2835932010-12-13 16:28:46 -08001767 * @param flags Information about what to return. May be any combination
Dianne Hackborn805fd7e2011-01-16 18:30:29 -08001768 * of {@link #RECENT_WITH_EXCLUDED} and {@link #RECENT_IGNORE_UNAVAILABLE}.
Stefan Kuhne16045c22015-06-05 07:18:06 -07001769 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001770 * @return Returns a list of RecentTaskInfo records describing each of
1771 * the recent tasks.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001772 */
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001773 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001774 public List<RecentTaskInfo> getRecentTasks(int maxNum, int flags)
1775 throws SecurityException {
1776 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001777 return getService().getRecentTasks(maxNum,
Jeff Sharkey479212c2016-06-29 16:00:55 -06001778 flags, UserHandle.myUserId()).getList();
Amith Yamasani82644082012-08-03 13:09:11 -07001779 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001780 throw e.rethrowFromSystemServer();
Amith Yamasani82644082012-08-03 13:09:11 -07001781 }
1782 }
1783
1784 /**
1785 * Same as {@link #getRecentTasks(int, int)} but returns the recent tasks for a
1786 * specific user. It requires holding
1787 * the {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permission.
1788 * @param maxNum The maximum number of entries to return in the list. The
1789 * actual number returned may be smaller, depending on how many tasks the
1790 * user has started and the maximum number the system can remember.
1791 * @param flags Information about what to return. May be any combination
1792 * of {@link #RECENT_WITH_EXCLUDED} and {@link #RECENT_IGNORE_UNAVAILABLE}.
1793 *
1794 * @return Returns a list of RecentTaskInfo records describing each of
Vadim Tryshev35605752015-08-31 13:28:08 -07001795 * the recent tasks. Most recently activated tasks go first.
Amith Yamasani82644082012-08-03 13:09:11 -07001796 *
Amith Yamasani82644082012-08-03 13:09:11 -07001797 * @hide
1798 */
1799 public List<RecentTaskInfo> getRecentTasksForUser(int maxNum, int flags, int userId)
1800 throws SecurityException {
1801 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001802 return getService().getRecentTasks(maxNum,
Jeff Sharkey479212c2016-06-29 16:00:55 -06001803 flags, userId).getList();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001804 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001805 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001806 }
1807 }
1808
1809 /**
1810 * Information you can retrieve about a particular task that is currently
1811 * "running" in the system. Note that a running task does not mean the
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07001812 * given task actually has a process it is actively running in; it simply
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001813 * means that the user has gone to it and never closed it, but currently
1814 * the system may have killed its process and is only holding on to its
1815 * last state in order to restart it when the user returns.
1816 */
1817 public static class RunningTaskInfo implements Parcelable {
1818 /**
1819 * A unique identifier for this task.
1820 */
1821 public int id;
1822
1823 /**
Winson5510f6c2015-10-27 12:11:26 -07001824 * The stack that currently contains this task.
1825 * @hide
1826 */
1827 public int stackId;
1828
1829 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001830 * The component launched as the first activity in the task. This can
1831 * be considered the "application" of this task.
1832 */
1833 public ComponentName baseActivity;
1834
1835 /**
1836 * The activity component at the top of the history stack of the task.
1837 * This is what the user is currently doing.
1838 */
1839 public ComponentName topActivity;
1840
1841 /**
Dianne Hackborn805fd7e2011-01-16 18:30:29 -08001842 * Thumbnail representation of the task's current state. Currently
1843 * always null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001844 */
1845 public Bitmap thumbnail;
1846
1847 /**
1848 * Description of the task's current state.
1849 */
1850 public CharSequence description;
1851
1852 /**
1853 * Number of activities in this task.
1854 */
1855 public int numActivities;
1856
1857 /**
1858 * Number of activities that are currently running (not stopped
1859 * and persisted) in this task.
1860 */
1861 public int numRunning;
1862
Craig Mautnerc0fd8052013-09-19 11:20:17 -07001863 /**
1864 * Last time task was run. For sorting.
1865 * @hide
1866 */
1867 public long lastActiveTime;
1868
Wale Ogunwale21b60582016-01-27 12:34:16 -08001869 /**
1870 * True if the task can go in the docked stack.
1871 * @hide
1872 */
Winson Chungd3395382016-12-13 11:49:09 -08001873 public boolean supportsSplitScreenMultiWindow;
Wale Ogunwale21b60582016-01-27 12:34:16 -08001874
Jorim Jaggi29379ec2016-04-11 23:43:42 -07001875 /**
1876 * The resize mode of the task. See {@link ActivityInfo#resizeMode}.
1877 * @hide
1878 */
1879 public int resizeMode;
1880
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001881 public RunningTaskInfo() {
1882 }
1883
1884 public int describeContents() {
1885 return 0;
1886 }
1887
1888 public void writeToParcel(Parcel dest, int flags) {
1889 dest.writeInt(id);
Winson5510f6c2015-10-27 12:11:26 -07001890 dest.writeInt(stackId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001891 ComponentName.writeToParcel(baseActivity, dest);
1892 ComponentName.writeToParcel(topActivity, dest);
1893 if (thumbnail != null) {
1894 dest.writeInt(1);
1895 thumbnail.writeToParcel(dest, 0);
1896 } else {
1897 dest.writeInt(0);
1898 }
1899 TextUtils.writeToParcel(description, dest,
1900 Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
1901 dest.writeInt(numActivities);
1902 dest.writeInt(numRunning);
Winson Chungd3395382016-12-13 11:49:09 -08001903 dest.writeInt(supportsSplitScreenMultiWindow ? 1 : 0);
Jorim Jaggi29379ec2016-04-11 23:43:42 -07001904 dest.writeInt(resizeMode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001905 }
1906
1907 public void readFromParcel(Parcel source) {
1908 id = source.readInt();
Winson5510f6c2015-10-27 12:11:26 -07001909 stackId = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001910 baseActivity = ComponentName.readFromParcel(source);
1911 topActivity = ComponentName.readFromParcel(source);
1912 if (source.readInt() != 0) {
1913 thumbnail = Bitmap.CREATOR.createFromParcel(source);
1914 } else {
1915 thumbnail = null;
1916 }
1917 description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
1918 numActivities = source.readInt();
1919 numRunning = source.readInt();
Winson Chungd3395382016-12-13 11:49:09 -08001920 supportsSplitScreenMultiWindow = source.readInt() != 0;
Jorim Jaggi29379ec2016-04-11 23:43:42 -07001921 resizeMode = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001922 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07001923
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001924 public static final Creator<RunningTaskInfo> CREATOR = new Creator<RunningTaskInfo>() {
1925 public RunningTaskInfo createFromParcel(Parcel source) {
1926 return new RunningTaskInfo(source);
1927 }
1928 public RunningTaskInfo[] newArray(int size) {
1929 return new RunningTaskInfo[size];
1930 }
1931 };
1932
1933 private RunningTaskInfo(Parcel source) {
1934 readFromParcel(source);
1935 }
1936 }
Winson Chung1147c402014-05-14 11:05:00 -07001937
1938 /**
1939 * Get the list of tasks associated with the calling application.
1940 *
1941 * @return The list of tasks associated with the application making this call.
1942 * @throws SecurityException
1943 */
1944 public List<ActivityManager.AppTask> getAppTasks() {
1945 ArrayList<AppTask> tasks = new ArrayList<AppTask>();
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07001946 List<IBinder> appTasks;
Winson Chung1147c402014-05-14 11:05:00 -07001947 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001948 appTasks = getService().getAppTasks(mContext.getPackageName());
Winson Chung1147c402014-05-14 11:05:00 -07001949 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001950 throw e.rethrowFromSystemServer();
Winson Chung1147c402014-05-14 11:05:00 -07001951 }
1952 int numAppTasks = appTasks.size();
1953 for (int i = 0; i < numAppTasks; i++) {
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07001954 tasks.add(new AppTask(IAppTask.Stub.asInterface(appTasks.get(i))));
Winson Chung1147c402014-05-14 11:05:00 -07001955 }
1956 return tasks;
1957 }
1958
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001959 /**
Winson Chung48a10a52014-08-27 14:36:51 -07001960 * Return the current design dimensions for {@link AppTask} thumbnails, for use
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001961 * with {@link #addAppTask}.
1962 */
Winson Chung48a10a52014-08-27 14:36:51 -07001963 public Size getAppTaskThumbnailSize() {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001964 synchronized (this) {
1965 ensureAppTaskThumbnailSizeLocked();
Winson Chung48a10a52014-08-27 14:36:51 -07001966 return new Size(mAppTaskThumbnailSize.x, mAppTaskThumbnailSize.y);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001967 }
1968 }
1969
1970 private void ensureAppTaskThumbnailSizeLocked() {
1971 if (mAppTaskThumbnailSize == null) {
1972 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001973 mAppTaskThumbnailSize = getService().getAppTaskThumbnailSize();
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001974 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001975 throw e.rethrowFromSystemServer();
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001976 }
1977 }
1978 }
1979
1980 /**
1981 * Add a new {@link AppTask} for the calling application. This will create a new
1982 * recents entry that is added to the <b>end</b> of all existing recents.
1983 *
1984 * @param activity The activity that is adding the entry. This is used to help determine
1985 * the context that the new recents entry will be in.
1986 * @param intent The Intent that describes the recents entry. This is the same Intent that
1987 * you would have used to launch the activity for it. In generally you will want to set
1988 * both {@link Intent#FLAG_ACTIVITY_NEW_DOCUMENT} and
1989 * {@link Intent#FLAG_ACTIVITY_RETAIN_IN_RECENTS}; the latter is required since this recents
1990 * entry will exist without an activity, so it doesn't make sense to not retain it when
1991 * its activity disappears. The given Intent here also must have an explicit ComponentName
1992 * set on it.
1993 * @param description Optional additional description information.
1994 * @param thumbnail Thumbnail to use for the recents entry. Should be the size given by
Winson Chung48a10a52014-08-27 14:36:51 -07001995 * {@link #getAppTaskThumbnailSize()}. If the bitmap is not that exact size, it will be
1996 * recreated in your process, probably in a way you don't like, before the recents entry
1997 * is added.
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001998 *
1999 * @return Returns the task id of the newly added app task, or -1 if the add failed. The
2000 * most likely cause of failure is that there is no more room for more tasks for your app.
2001 */
2002 public int addAppTask(@NonNull Activity activity, @NonNull Intent intent,
2003 @Nullable TaskDescription description, @NonNull Bitmap thumbnail) {
2004 Point size;
2005 synchronized (this) {
2006 ensureAppTaskThumbnailSizeLocked();
2007 size = mAppTaskThumbnailSize;
2008 }
2009 final int tw = thumbnail.getWidth();
2010 final int th = thumbnail.getHeight();
2011 if (tw != size.x || th != size.y) {
2012 Bitmap bm = Bitmap.createBitmap(size.x, size.y, thumbnail.getConfig());
2013
2014 // Use ScaleType.CENTER_CROP, except we leave the top edge at the top.
2015 float scale;
2016 float dx = 0, dy = 0;
2017 if (tw * size.x > size.y * th) {
2018 scale = (float) size.x / (float) th;
2019 dx = (size.y - tw * scale) * 0.5f;
2020 } else {
2021 scale = (float) size.y / (float) tw;
2022 dy = (size.x - th * scale) * 0.5f;
2023 }
2024 Matrix matrix = new Matrix();
2025 matrix.setScale(scale, scale);
2026 matrix.postTranslate((int) (dx + 0.5f), 0);
2027
2028 Canvas canvas = new Canvas(bm);
2029 canvas.drawBitmap(thumbnail, matrix, null);
2030 canvas.setBitmap(null);
2031
2032 thumbnail = bm;
2033 }
2034 if (description == null) {
2035 description = new TaskDescription();
2036 }
2037 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002038 return getService().addAppTask(activity.getActivityToken(),
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002039 intent, description, thumbnail);
2040 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002041 throw e.rethrowFromSystemServer();
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002042 }
2043 }
2044
2045 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002046 * Return a list of the tasks that are currently running, with
2047 * the most recent being first and older ones after in order. Note that
2048 * "running" does not mean any of the task's code is currently loaded or
2049 * activity -- the task may have been frozen by the system, so that it
2050 * can be restarted in its previous state when next brought to the
2051 * foreground.
Jim Miller0b2a6d02010-07-13 18:01:29 -07002052 *
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07002053 * <p><b>Note: this method is only intended for debugging and presenting
2054 * task management user interfaces</b>. This should never be used for
2055 * core logic in an application, such as deciding between different
2056 * behaviors based on the information found here. Such uses are
2057 * <em>not</em> supported, and will likely break in the future. For
2058 * example, if multiple applications can be actively running at the
2059 * same time, assumptions made about the meaning of the data here for
2060 * purposes of control flow will be incorrect.</p>
2061 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07002062 * @deprecated As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method
Dianne Hackborna25a8b22014-05-30 12:30:35 -07002063 * is no longer available to third party
2064 * applications: the introduction of document-centric recents means
2065 * it can leak person information to the caller. For backwards compatibility,
Alan Stokes1e4e74a2017-08-02 11:17:37 +01002066 * it will still return a small subset of its data: at least the caller's
Dianne Hackborna25a8b22014-05-30 12:30:35 -07002067 * own tasks, and possibly some other tasks
2068 * such as home that are known to not be sensitive.
2069 *
Jim Miller0b2a6d02010-07-13 18:01:29 -07002070 * @param maxNum The maximum number of entries to return in the list. The
2071 * actual number returned may be smaller, depending on how many tasks the
2072 * user has started.
2073 *
2074 * @return Returns a list of RunningTaskInfo records describing each of
2075 * the running tasks.
Jim Miller0b2a6d02010-07-13 18:01:29 -07002076 */
Dianne Hackborna25a8b22014-05-30 12:30:35 -07002077 @Deprecated
Jim Miller0b2a6d02010-07-13 18:01:29 -07002078 public List<RunningTaskInfo> getRunningTasks(int maxNum)
2079 throws SecurityException {
Dianne Hackborn09233282014-04-30 11:33:59 -07002080 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002081 return getService().getTasks(maxNum, 0);
Dianne Hackborn09233282014-04-30 11:33:59 -07002082 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002083 throw e.rethrowFromSystemServer();
Dianne Hackborn09233282014-04-30 11:33:59 -07002084 }
Jim Miller0b2a6d02010-07-13 18:01:29 -07002085 }
2086
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002087 /**
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002088 * Completely remove the given task.
2089 *
2090 * @param taskId Identifier of the task to be removed.
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002091 * @return Returns true if the given task was found and removed.
2092 *
2093 * @hide
2094 */
Wale Ogunwaled54b5782014-10-23 15:55:23 -07002095 public boolean removeTask(int taskId) throws SecurityException {
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002096 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002097 return getService().removeTask(taskId);
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002098 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002099 throw e.rethrowFromSystemServer();
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002100 }
2101 }
2102
Winsonc809cbb2015-11-02 12:06:15 -08002103 /**
2104 * Metadata related to the {@link TaskThumbnail}.
2105 *
2106 * @hide
2107 */
2108 public static class TaskThumbnailInfo implements Parcelable {
2109 /** @hide */
2110 public static final String ATTR_TASK_THUMBNAILINFO_PREFIX = "task_thumbnailinfo_";
2111 private static final String ATTR_TASK_WIDTH =
2112 ATTR_TASK_THUMBNAILINFO_PREFIX + "task_width";
2113 private static final String ATTR_TASK_HEIGHT =
2114 ATTR_TASK_THUMBNAILINFO_PREFIX + "task_height";
2115 private static final String ATTR_SCREEN_ORIENTATION =
2116 ATTR_TASK_THUMBNAILINFO_PREFIX + "screen_orientation";
2117
2118 public int taskWidth;
2119 public int taskHeight;
Winson21700932016-03-24 17:26:23 -07002120 public int screenOrientation = Configuration.ORIENTATION_UNDEFINED;
Winsonc809cbb2015-11-02 12:06:15 -08002121
2122 public TaskThumbnailInfo() {
2123 // Do nothing
2124 }
2125
2126 private TaskThumbnailInfo(Parcel source) {
2127 readFromParcel(source);
2128 }
2129
Winsonc6a2da02015-11-11 18:11:59 -08002130 /**
2131 * Resets this info state to the initial state.
2132 * @hide
2133 */
2134 public void reset() {
2135 taskWidth = 0;
2136 taskHeight = 0;
Winson21700932016-03-24 17:26:23 -07002137 screenOrientation = Configuration.ORIENTATION_UNDEFINED;
2138 }
2139
2140 /**
2141 * Copies from another ThumbnailInfo.
2142 */
2143 public void copyFrom(TaskThumbnailInfo o) {
2144 taskWidth = o.taskWidth;
2145 taskHeight = o.taskHeight;
2146 screenOrientation = o.screenOrientation;
Winsonc6a2da02015-11-11 18:11:59 -08002147 }
2148
Winsonc809cbb2015-11-02 12:06:15 -08002149 /** @hide */
2150 public void saveToXml(XmlSerializer out) throws IOException {
2151 out.attribute(null, ATTR_TASK_WIDTH, Integer.toString(taskWidth));
2152 out.attribute(null, ATTR_TASK_HEIGHT, Integer.toString(taskHeight));
2153 out.attribute(null, ATTR_SCREEN_ORIENTATION, Integer.toString(screenOrientation));
2154 }
2155
2156 /** @hide */
2157 public void restoreFromXml(String attrName, String attrValue) {
2158 if (ATTR_TASK_WIDTH.equals(attrName)) {
2159 taskWidth = Integer.parseInt(attrValue);
2160 } else if (ATTR_TASK_HEIGHT.equals(attrName)) {
2161 taskHeight = Integer.parseInt(attrValue);
2162 } else if (ATTR_SCREEN_ORIENTATION.equals(attrName)) {
2163 screenOrientation = Integer.parseInt(attrValue);
2164 }
2165 }
2166
2167 public int describeContents() {
2168 return 0;
2169 }
2170
2171 public void writeToParcel(Parcel dest, int flags) {
2172 dest.writeInt(taskWidth);
2173 dest.writeInt(taskHeight);
2174 dest.writeInt(screenOrientation);
2175 }
2176
2177 public void readFromParcel(Parcel source) {
2178 taskWidth = source.readInt();
2179 taskHeight = source.readInt();
2180 screenOrientation = source.readInt();
2181 }
2182
2183 public static final Creator<TaskThumbnailInfo> CREATOR = new Creator<TaskThumbnailInfo>() {
2184 public TaskThumbnailInfo createFromParcel(Parcel source) {
2185 return new TaskThumbnailInfo(source);
2186 }
2187 public TaskThumbnailInfo[] newArray(int size) {
2188 return new TaskThumbnailInfo[size];
2189 }
2190 };
2191 }
2192
Dianne Hackbornd94df452011-02-16 18:53:31 -08002193 /** @hide */
Craig Mautnerc0ffce52014-07-01 12:38:52 -07002194 public static class TaskThumbnail implements Parcelable {
Dianne Hackbornf26fd992011-04-08 18:14:09 -07002195 public Bitmap mainThumbnail;
Craig Mautnerc0ffce52014-07-01 12:38:52 -07002196 public ParcelFileDescriptor thumbnailFileDescriptor;
Winsonc809cbb2015-11-02 12:06:15 -08002197 public TaskThumbnailInfo thumbnailInfo;
Dianne Hackbornf26fd992011-04-08 18:14:09 -07002198
Craig Mautnerc0ffce52014-07-01 12:38:52 -07002199 public TaskThumbnail() {
Dianne Hackbornf26fd992011-04-08 18:14:09 -07002200 }
2201
Winsonc809cbb2015-11-02 12:06:15 -08002202 private TaskThumbnail(Parcel source) {
2203 readFromParcel(source);
2204 }
2205
Dianne Hackbornf26fd992011-04-08 18:14:09 -07002206 public int describeContents() {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07002207 if (thumbnailFileDescriptor != null) {
2208 return thumbnailFileDescriptor.describeContents();
2209 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -07002210 return 0;
2211 }
2212
2213 public void writeToParcel(Parcel dest, int flags) {
2214 if (mainThumbnail != null) {
2215 dest.writeInt(1);
Dianne Hackborn852975d2014-08-22 17:42:43 -07002216 mainThumbnail.writeToParcel(dest, flags);
Dianne Hackbornf26fd992011-04-08 18:14:09 -07002217 } else {
2218 dest.writeInt(0);
2219 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07002220 if (thumbnailFileDescriptor != null) {
2221 dest.writeInt(1);
Dianne Hackborn852975d2014-08-22 17:42:43 -07002222 thumbnailFileDescriptor.writeToParcel(dest, flags);
Craig Mautnerc0ffce52014-07-01 12:38:52 -07002223 } else {
2224 dest.writeInt(0);
2225 }
Winsonc809cbb2015-11-02 12:06:15 -08002226 if (thumbnailInfo != null) {
2227 dest.writeInt(1);
2228 thumbnailInfo.writeToParcel(dest, flags);
2229 } else {
2230 dest.writeInt(0);
2231 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -07002232 }
2233
2234 public void readFromParcel(Parcel source) {
2235 if (source.readInt() != 0) {
2236 mainThumbnail = Bitmap.CREATOR.createFromParcel(source);
2237 } else {
2238 mainThumbnail = null;
2239 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07002240 if (source.readInt() != 0) {
2241 thumbnailFileDescriptor = ParcelFileDescriptor.CREATOR.createFromParcel(source);
2242 } else {
2243 thumbnailFileDescriptor = null;
2244 }
Winsonc809cbb2015-11-02 12:06:15 -08002245 if (source.readInt() != 0) {
2246 thumbnailInfo = TaskThumbnailInfo.CREATOR.createFromParcel(source);
2247 } else {
2248 thumbnailInfo = null;
2249 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -07002250 }
2251
Craig Mautnerc0ffce52014-07-01 12:38:52 -07002252 public static final Creator<TaskThumbnail> CREATOR = new Creator<TaskThumbnail>() {
2253 public TaskThumbnail createFromParcel(Parcel source) {
2254 return new TaskThumbnail(source);
Dianne Hackbornf26fd992011-04-08 18:14:09 -07002255 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07002256 public TaskThumbnail[] newArray(int size) {
2257 return new TaskThumbnail[size];
Dianne Hackbornf26fd992011-04-08 18:14:09 -07002258 }
2259 };
Dianne Hackbornf26fd992011-04-08 18:14:09 -07002260 }
2261
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002262 /**
2263 * Represents a task snapshot.
2264 * @hide
2265 */
2266 public static class TaskSnapshot implements Parcelable {
2267
2268 private final GraphicBuffer mSnapshot;
2269 private final int mOrientation;
2270 private final Rect mContentInsets;
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002271 private final boolean mReducedResolution;
2272 private final float mScale;
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002273
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002274 public TaskSnapshot(GraphicBuffer snapshot, int orientation, Rect contentInsets,
2275 boolean reducedResolution, float scale) {
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002276 mSnapshot = snapshot;
2277 mOrientation = orientation;
2278 mContentInsets = new Rect(contentInsets);
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002279 mReducedResolution = reducedResolution;
2280 mScale = scale;
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002281 }
2282
2283 private TaskSnapshot(Parcel source) {
2284 mSnapshot = source.readParcelable(null /* classLoader */);
2285 mOrientation = source.readInt();
2286 mContentInsets = source.readParcelable(null /* classLoader */);
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002287 mReducedResolution = source.readBoolean();
2288 mScale = source.readFloat();
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002289 }
2290
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002291 /**
2292 * @return The graphic buffer representing the screenshot.
2293 */
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002294 public GraphicBuffer getSnapshot() {
2295 return mSnapshot;
2296 }
2297
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002298 /**
2299 * @return The screen orientation the screenshot was taken in.
2300 */
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002301 public int getOrientation() {
2302 return mOrientation;
2303 }
2304
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002305 /**
2306 * @return The system/content insets on the snapshot. These can be clipped off in order to
2307 * remove any areas behind system bars in the snapshot.
2308 */
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002309 public Rect getContentInsets() {
2310 return mContentInsets;
2311 }
2312
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002313 /**
2314 * @return Whether this snapshot is a down-sampled version of the full resolution.
2315 */
2316 public boolean isReducedResolution() {
2317 return mReducedResolution;
2318 }
2319
2320 /**
2321 * @return The scale this snapshot was taken in.
2322 */
2323 public float getScale() {
2324 return mScale;
2325 }
2326
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002327 @Override
2328 public int describeContents() {
2329 return 0;
2330 }
2331
2332 @Override
2333 public void writeToParcel(Parcel dest, int flags) {
2334 dest.writeParcelable(mSnapshot, 0);
2335 dest.writeInt(mOrientation);
2336 dest.writeParcelable(mContentInsets, 0);
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002337 dest.writeBoolean(mReducedResolution);
2338 dest.writeFloat(mScale);
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002339 }
2340
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01002341 @Override
2342 public String toString() {
2343 return "TaskSnapshot{mSnapshot=" + mSnapshot + " mOrientation=" + mOrientation
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002344 + " mContentInsets=" + mContentInsets.toShortString()
2345 + " mReducedResolution=" + mReducedResolution + " mScale=" + mScale;
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01002346 }
2347
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002348 public static final Creator<TaskSnapshot> CREATOR = new Creator<TaskSnapshot>() {
2349 public TaskSnapshot createFromParcel(Parcel source) {
2350 return new TaskSnapshot(source);
2351 }
2352 public TaskSnapshot[] newArray(int size) {
2353 return new TaskSnapshot[size];
2354 }
2355 };
2356 }
2357
Dianne Hackbornf26fd992011-04-08 18:14:09 -07002358 /** @hide */
Craig Mautnerc0ffce52014-07-01 12:38:52 -07002359 public TaskThumbnail getTaskThumbnail(int id) throws SecurityException {
Dianne Hackbornd94df452011-02-16 18:53:31 -08002360 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002361 return getService().getTaskThumbnail(id);
Dianne Hackborn15491c62012-09-19 10:59:14 -07002362 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002363 throw e.rethrowFromSystemServer();
Dianne Hackborn15491c62012-09-19 10:59:14 -07002364 }
2365 }
2366
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002367 /** @hide */
2368 @IntDef(flag = true, prefix = { "MOVE_TASK_" }, value = {
2369 MOVE_TASK_WITH_HOME,
2370 MOVE_TASK_NO_USER_ACTION,
2371 })
2372 @Retention(RetentionPolicy.SOURCE)
2373 public @interface MoveTaskFlags {}
2374
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002375 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002376 * Flag for {@link #moveTaskToFront(int, int)}: also move the "home"
2377 * activity along with the task, so it is positioned immediately behind
2378 * the task.
2379 */
2380 public static final int MOVE_TASK_WITH_HOME = 0x00000001;
2381
2382 /**
Dianne Hackbornd94df452011-02-16 18:53:31 -08002383 * Flag for {@link #moveTaskToFront(int, int)}: don't count this as a
2384 * user-instigated action, so the current activity will not receive a
2385 * hint that the user is leaving.
2386 */
2387 public static final int MOVE_TASK_NO_USER_ACTION = 0x00000002;
2388
2389 /**
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07002390 * Equivalent to calling {@link #moveTaskToFront(int, int, Bundle)}
2391 * with a null options argument.
2392 *
2393 * @param taskId The identifier of the task to be moved, as found in
2394 * {@link RunningTaskInfo} or {@link RecentTaskInfo}.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002395 * @param flags Additional operational flags.
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07002396 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002397 @RequiresPermission(android.Manifest.permission.REORDER_TASKS)
2398 public void moveTaskToFront(int taskId, @MoveTaskFlags int flags) {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07002399 moveTaskToFront(taskId, flags, null);
2400 }
2401
2402 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002403 * Ask that the task associated with a given task ID be moved to the
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002404 * front of the stack, so it is now visible to the user.
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002405 *
2406 * @param taskId The identifier of the task to be moved, as found in
2407 * {@link RunningTaskInfo} or {@link RecentTaskInfo}.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002408 * @param flags Additional operational flags.
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07002409 * @param options Additional options for the operation, either null or
2410 * as per {@link Context#startActivity(Intent, android.os.Bundle)
2411 * Context.startActivity(Intent, Bundle)}.
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002412 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002413 @RequiresPermission(android.Manifest.permission.REORDER_TASKS)
2414 public void moveTaskToFront(int taskId, @MoveTaskFlags int flags, Bundle options) {
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002415 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002416 getService().moveTaskToFront(taskId, flags, options);
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002417 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002418 throw e.rethrowFromSystemServer();
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002419 }
2420 }
2421
2422 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002423 * Information you can retrieve about a particular Service that is
2424 * currently running in the system.
2425 */
2426 public static class RunningServiceInfo implements Parcelable {
2427 /**
2428 * The service component.
2429 */
2430 public ComponentName service;
2431
2432 /**
2433 * If non-zero, this is the process the service is running in.
2434 */
2435 public int pid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002436
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002437 /**
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002438 * The UID that owns this service.
2439 */
2440 public int uid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002441
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002442 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002443 * The name of the process this service runs in.
2444 */
2445 public String process;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002446
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002447 /**
2448 * Set to true if the service has asked to run as a foreground process.
2449 */
2450 public boolean foreground;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002451
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002452 /**
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002453 * The time when the service was first made active, either by someone
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07002454 * starting or binding to it. This
2455 * is in units of {@link android.os.SystemClock#elapsedRealtime()}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002456 */
2457 public long activeSince;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002458
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002459 /**
2460 * Set to true if this service has been explicitly started.
2461 */
2462 public boolean started;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002463
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002464 /**
2465 * Number of clients connected to the service.
2466 */
2467 public int clientCount;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002468
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002469 /**
2470 * Number of times the service's process has crashed while the service
2471 * is running.
2472 */
2473 public int crashCount;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002474
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002475 /**
2476 * The time when there was last activity in the service (either
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07002477 * explicit requests to start it or clients binding to it). This
2478 * is in units of {@link android.os.SystemClock#uptimeMillis()}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002479 */
2480 public long lastActivityTime;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002482 /**
2483 * If non-zero, this service is not currently running, but scheduled to
2484 * restart at the given time.
2485 */
2486 public long restarting;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002487
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002488 /**
2489 * Bit for {@link #flags}: set if this service has been
2490 * explicitly started.
2491 */
2492 public static final int FLAG_STARTED = 1<<0;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002493
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002494 /**
2495 * Bit for {@link #flags}: set if the service has asked to
2496 * run as a foreground process.
2497 */
2498 public static final int FLAG_FOREGROUND = 1<<1;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002499
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002500 /**
Elliot Waite54de7742017-01-11 15:30:35 -08002501 * Bit for {@link #flags}: set if the service is running in a
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002502 * core system process.
2503 */
2504 public static final int FLAG_SYSTEM_PROCESS = 1<<2;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002505
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002506 /**
Elliot Waite54de7742017-01-11 15:30:35 -08002507 * Bit for {@link #flags}: set if the service is running in a
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002508 * persistent process.
2509 */
2510 public static final int FLAG_PERSISTENT_PROCESS = 1<<3;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002511
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002512 /**
2513 * Running flags.
2514 */
2515 public int flags;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002516
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002517 /**
2518 * For special services that are bound to by system code, this is
2519 * the package that holds the binding.
2520 */
2521 public String clientPackage;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002522
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002523 /**
2524 * For special services that are bound to by system code, this is
2525 * a string resource providing a user-visible label for who the
2526 * client is.
2527 */
2528 public int clientLabel;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002529
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002530 public RunningServiceInfo() {
2531 }
2532
2533 public int describeContents() {
2534 return 0;
2535 }
2536
2537 public void writeToParcel(Parcel dest, int flags) {
2538 ComponentName.writeToParcel(service, dest);
2539 dest.writeInt(pid);
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002540 dest.writeInt(uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002541 dest.writeString(process);
2542 dest.writeInt(foreground ? 1 : 0);
2543 dest.writeLong(activeSince);
2544 dest.writeInt(started ? 1 : 0);
2545 dest.writeInt(clientCount);
2546 dest.writeInt(crashCount);
2547 dest.writeLong(lastActivityTime);
2548 dest.writeLong(restarting);
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002549 dest.writeInt(this.flags);
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002550 dest.writeString(clientPackage);
2551 dest.writeInt(clientLabel);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002552 }
2553
2554 public void readFromParcel(Parcel source) {
2555 service = ComponentName.readFromParcel(source);
2556 pid = source.readInt();
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002557 uid = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002558 process = source.readString();
2559 foreground = source.readInt() != 0;
2560 activeSince = source.readLong();
2561 started = source.readInt() != 0;
2562 clientCount = source.readInt();
2563 crashCount = source.readInt();
2564 lastActivityTime = source.readLong();
2565 restarting = source.readLong();
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002566 flags = source.readInt();
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002567 clientPackage = source.readString();
2568 clientLabel = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002569 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002570
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002571 public static final Creator<RunningServiceInfo> CREATOR = new Creator<RunningServiceInfo>() {
2572 public RunningServiceInfo createFromParcel(Parcel source) {
2573 return new RunningServiceInfo(source);
2574 }
2575 public RunningServiceInfo[] newArray(int size) {
2576 return new RunningServiceInfo[size];
2577 }
2578 };
2579
2580 private RunningServiceInfo(Parcel source) {
2581 readFromParcel(source);
2582 }
2583 }
2584
2585 /**
2586 * Return a list of the services that are currently running.
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07002587 *
2588 * <p><b>Note: this method is only intended for debugging or implementing
2589 * service management type user interfaces.</b></p>
2590 *
Bryce Leef17e1d1a42017-04-17 15:52:50 -07002591 * @deprecated As of {@link android.os.Build.VERSION_CODES#O}, this method
2592 * is no longer available to third party applications. For backwards compatibility,
2593 * it will still return the caller's own services.
2594 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002595 * @param maxNum The maximum number of entries to return in the list. The
2596 * actual number returned may be smaller, depending on how many services
2597 * are running.
Stefan Kuhne16045c22015-06-05 07:18:06 -07002598 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002599 * @return Returns a list of RunningServiceInfo records describing each of
2600 * the running tasks.
2601 */
Bryce Leef17e1d1a42017-04-17 15:52:50 -07002602 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002603 public List<RunningServiceInfo> getRunningServices(int maxNum)
2604 throws SecurityException {
2605 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002606 return getService()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002607 .getServices(maxNum, 0);
2608 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002609 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002610 }
2611 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002612
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002613 /**
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002614 * Returns a PendingIntent you can start to show a control panel for the
2615 * given running service. If the service does not have a control panel,
2616 * null is returned.
2617 */
2618 public PendingIntent getRunningServiceControlPanel(ComponentName service)
2619 throws SecurityException {
2620 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002621 return getService()
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002622 .getRunningServiceControlPanel(service);
2623 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002624 throw e.rethrowFromSystemServer();
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002625 }
2626 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002627
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002628 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002629 * Information you can retrieve about the available memory through
2630 * {@link ActivityManager#getMemoryInfo}.
2631 */
2632 public static class MemoryInfo implements Parcelable {
2633 /**
Dianne Hackborn59325eb2012-05-09 18:45:20 -07002634 * The available memory on the system. This number should not
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002635 * be considered absolute: due to the nature of the kernel, a significant
2636 * portion of this memory is actually in use and needed for the overall
2637 * system to run well.
2638 */
2639 public long availMem;
Dianne Hackborn59325eb2012-05-09 18:45:20 -07002640
2641 /**
2642 * The total memory accessible by the kernel. This is basically the
2643 * RAM size of the device, not including below-kernel fixed allocations
2644 * like DMA buffers, RAM for the baseband CPU, etc.
2645 */
2646 public long totalMem;
2647
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002648 /**
2649 * The threshold of {@link #availMem} at which we consider memory to be
2650 * low and start killing background services and other non-extraneous
2651 * processes.
2652 */
2653 public long threshold;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002654
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002655 /**
2656 * Set to true if the system considers itself to currently be in a low
2657 * memory situation.
2658 */
2659 public boolean lowMemory;
2660
Dianne Hackborn7d608422011-08-07 16:24:18 -07002661 /** @hide */
2662 public long hiddenAppThreshold;
2663 /** @hide */
2664 public long secondaryServerThreshold;
2665 /** @hide */
2666 public long visibleAppThreshold;
2667 /** @hide */
2668 public long foregroundAppThreshold;
2669
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002670 public MemoryInfo() {
2671 }
2672
2673 public int describeContents() {
2674 return 0;
2675 }
2676
2677 public void writeToParcel(Parcel dest, int flags) {
2678 dest.writeLong(availMem);
Dianne Hackborn59325eb2012-05-09 18:45:20 -07002679 dest.writeLong(totalMem);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002680 dest.writeLong(threshold);
2681 dest.writeInt(lowMemory ? 1 : 0);
Dianne Hackborn7d608422011-08-07 16:24:18 -07002682 dest.writeLong(hiddenAppThreshold);
2683 dest.writeLong(secondaryServerThreshold);
2684 dest.writeLong(visibleAppThreshold);
2685 dest.writeLong(foregroundAppThreshold);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002686 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002687
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002688 public void readFromParcel(Parcel source) {
2689 availMem = source.readLong();
Dianne Hackborn59325eb2012-05-09 18:45:20 -07002690 totalMem = source.readLong();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002691 threshold = source.readLong();
2692 lowMemory = source.readInt() != 0;
Dianne Hackborn7d608422011-08-07 16:24:18 -07002693 hiddenAppThreshold = source.readLong();
2694 secondaryServerThreshold = source.readLong();
2695 visibleAppThreshold = source.readLong();
2696 foregroundAppThreshold = source.readLong();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002697 }
2698
2699 public static final Creator<MemoryInfo> CREATOR
2700 = new Creator<MemoryInfo>() {
2701 public MemoryInfo createFromParcel(Parcel source) {
2702 return new MemoryInfo(source);
2703 }
2704 public MemoryInfo[] newArray(int size) {
2705 return new MemoryInfo[size];
2706 }
2707 };
2708
2709 private MemoryInfo(Parcel source) {
2710 readFromParcel(source);
2711 }
2712 }
2713
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07002714 /**
2715 * Return general information about the memory state of the system. This
2716 * can be used to help decide how to manage your own memory, though note
2717 * that polling is not recommended and
2718 * {@link android.content.ComponentCallbacks2#onTrimMemory(int)
2719 * ComponentCallbacks2.onTrimMemory(int)} is the preferred way to do this.
2720 * Also see {@link #getMyMemoryState} for how to retrieve the current trim
2721 * level of your process as needed, which gives a better hint for how to
2722 * manage its memory.
2723 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002724 public void getMemoryInfo(MemoryInfo outInfo) {
2725 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002726 getService().getMemoryInfo(outInfo);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002727 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002728 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002729 }
2730 }
Craig Mautner967212c2013-04-13 21:10:58 -07002731
Craig Mautner5ff12102013-05-24 12:50:15 -07002732 /**
Craig Mautner967212c2013-04-13 21:10:58 -07002733 * Information you can retrieve about an ActivityStack in the system.
2734 * @hide
2735 */
2736 public static class StackInfo implements Parcelable {
2737 public int stackId;
Craig Mautnered6649f2013-12-02 14:08:25 -08002738 public Rect bounds = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -07002739 public int[] taskIds;
2740 public String[] taskNames;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002741 public Rect[] taskBounds;
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002742 public int[] taskUserIds;
Winsond46b7272016-04-20 11:54:27 -07002743 public ComponentName topActivity;
Craig Mautnered6649f2013-12-02 14:08:25 -08002744 public int displayId;
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002745 public int userId;
Winsond46b7272016-04-20 11:54:27 -07002746 public boolean visible;
Winson529c8e42016-05-17 11:08:40 -07002747 // Index of the stack in the display's stack list, can be used for comparison of stack order
2748 public int position;
Craig Mautner967212c2013-04-13 21:10:58 -07002749
Craig Mautner967212c2013-04-13 21:10:58 -07002750 @Override
2751 public int describeContents() {
2752 return 0;
2753 }
2754
2755 @Override
2756 public void writeToParcel(Parcel dest, int flags) {
2757 dest.writeInt(stackId);
2758 dest.writeInt(bounds.left);
2759 dest.writeInt(bounds.top);
2760 dest.writeInt(bounds.right);
2761 dest.writeInt(bounds.bottom);
2762 dest.writeIntArray(taskIds);
2763 dest.writeStringArray(taskNames);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002764 final int boundsCount = taskBounds == null ? 0 : taskBounds.length;
2765 dest.writeInt(boundsCount);
2766 for (int i = 0; i < boundsCount; i++) {
2767 dest.writeInt(taskBounds[i].left);
2768 dest.writeInt(taskBounds[i].top);
2769 dest.writeInt(taskBounds[i].right);
2770 dest.writeInt(taskBounds[i].bottom);
2771 }
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002772 dest.writeIntArray(taskUserIds);
Craig Mautnered6649f2013-12-02 14:08:25 -08002773 dest.writeInt(displayId);
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002774 dest.writeInt(userId);
Winsond46b7272016-04-20 11:54:27 -07002775 dest.writeInt(visible ? 1 : 0);
Winson529c8e42016-05-17 11:08:40 -07002776 dest.writeInt(position);
Winsond46b7272016-04-20 11:54:27 -07002777 if (topActivity != null) {
2778 dest.writeInt(1);
2779 topActivity.writeToParcel(dest, 0);
2780 } else {
2781 dest.writeInt(0);
2782 }
Craig Mautner967212c2013-04-13 21:10:58 -07002783 }
2784
2785 public void readFromParcel(Parcel source) {
2786 stackId = source.readInt();
2787 bounds = new Rect(
2788 source.readInt(), source.readInt(), source.readInt(), source.readInt());
2789 taskIds = source.createIntArray();
2790 taskNames = source.createStringArray();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002791 final int boundsCount = source.readInt();
2792 if (boundsCount > 0) {
2793 taskBounds = new Rect[boundsCount];
2794 for (int i = 0; i < boundsCount; i++) {
2795 taskBounds[i] = new Rect();
2796 taskBounds[i].set(
2797 source.readInt(), source.readInt(), source.readInt(), source.readInt());
2798 }
2799 } else {
2800 taskBounds = null;
2801 }
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002802 taskUserIds = source.createIntArray();
Craig Mautnered6649f2013-12-02 14:08:25 -08002803 displayId = source.readInt();
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002804 userId = source.readInt();
Winsond46b7272016-04-20 11:54:27 -07002805 visible = source.readInt() > 0;
Winson529c8e42016-05-17 11:08:40 -07002806 position = source.readInt();
Winsond46b7272016-04-20 11:54:27 -07002807 if (source.readInt() > 0) {
2808 topActivity = ComponentName.readFromParcel(source);
2809 }
Craig Mautner967212c2013-04-13 21:10:58 -07002810 }
2811
2812 public static final Creator<StackInfo> CREATOR = new Creator<StackInfo>() {
2813 @Override
2814 public StackInfo createFromParcel(Parcel source) {
2815 return new StackInfo(source);
2816 }
2817 @Override
2818 public StackInfo[] newArray(int size) {
2819 return new StackInfo[size];
2820 }
2821 };
2822
Craig Mautner5ff12102013-05-24 12:50:15 -07002823 public StackInfo() {
2824 }
2825
Craig Mautner967212c2013-04-13 21:10:58 -07002826 private StackInfo(Parcel source) {
2827 readFromParcel(source);
2828 }
2829
Craig Mautner5ff12102013-05-24 12:50:15 -07002830 public String toString(String prefix) {
Craig Mautner967212c2013-04-13 21:10:58 -07002831 StringBuilder sb = new StringBuilder(256);
Craig Mautner5ff12102013-05-24 12:50:15 -07002832 sb.append(prefix); sb.append("Stack id="); sb.append(stackId);
Craig Mautnered6649f2013-12-02 14:08:25 -08002833 sb.append(" bounds="); sb.append(bounds.toShortString());
2834 sb.append(" displayId="); sb.append(displayId);
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002835 sb.append(" userId="); sb.append(userId);
Craig Mautnered6649f2013-12-02 14:08:25 -08002836 sb.append("\n");
Craig Mautner5ff12102013-05-24 12:50:15 -07002837 prefix = prefix + " ";
Craig Mautner967212c2013-04-13 21:10:58 -07002838 for (int i = 0; i < taskIds.length; ++i) {
2839 sb.append(prefix); sb.append("taskId="); sb.append(taskIds[i]);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002840 sb.append(": "); sb.append(taskNames[i]);
2841 if (taskBounds != null) {
2842 sb.append(" bounds="); sb.append(taskBounds[i].toShortString());
2843 }
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002844 sb.append(" userId=").append(taskUserIds[i]);
Winsond46b7272016-04-20 11:54:27 -07002845 sb.append(" visible=").append(visible);
2846 if (topActivity != null) {
2847 sb.append(" topActivity=").append(topActivity);
2848 }
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002849 sb.append("\n");
Craig Mautner967212c2013-04-13 21:10:58 -07002850 }
2851 return sb.toString();
2852 }
Craig Mautner5ff12102013-05-24 12:50:15 -07002853
2854 @Override
2855 public String toString() {
2856 return toString("");
2857 }
Craig Mautner967212c2013-04-13 21:10:58 -07002858 }
2859
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002860 /**
2861 * @hide
2862 */
Svet Ganovf935a702017-08-22 12:15:58 -07002863 @RequiresPermission(anyOf={Manifest.permission.CLEAR_APP_USER_DATA,
2864 Manifest.permission.ACCESS_INSTANT_APPS})
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002865 public boolean clearApplicationUserData(String packageName, IPackageDataObserver observer) {
2866 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002867 return getService().clearApplicationUserData(packageName,
Dianne Hackborn41203752012-08-31 14:05:51 -07002868 observer, UserHandle.myUserId());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002869 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002870 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002871 }
2872 }
Christopher Tatea3664242013-06-26 15:00:18 -07002873
2874 /**
2875 * Permits an application to erase its own data from disk. This is equivalent to
Dianne Hackbornebc15ef2013-10-09 17:36:57 -07002876 * the user choosing to clear the app's data from within the device settings UI. It
2877 * erases all dynamic data associated with the app -- its private data and data in its
2878 * private area on external storage -- but does not remove the installed application
2879 * itself, nor any OBB files.
Christopher Tatea3664242013-06-26 15:00:18 -07002880 *
2881 * @return {@code true} if the application successfully requested that the application's
2882 * data be erased; {@code false} otherwise.
2883 */
2884 public boolean clearApplicationUserData() {
2885 return clearApplicationUserData(mContext.getPackageName(), null);
2886 }
2887
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002888
2889 /**
2890 * Permits an application to get the persistent URI permissions granted to another.
2891 *
2892 * <p>Typically called by Settings.
2893 *
2894 * @param packageName application to look for the granted permissions
2895 * @return list of granted URI permissions
2896 *
2897 * @hide
2898 */
2899 public ParceledListSlice<UriPermission> getGrantedUriPermissions(String packageName) {
2900 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002901 return getService().getGrantedUriPermissions(packageName,
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002902 UserHandle.myUserId());
2903 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002904 throw e.rethrowFromSystemServer();
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002905 }
2906 }
2907
2908 /**
2909 * Permits an application to clear the persistent URI permissions granted to another.
2910 *
2911 * <p>Typically called by Settings.
2912 *
2913 * @param packageName application to clear its granted permissions
2914 *
2915 * @hide
2916 */
2917 public void clearGrantedUriPermissions(String packageName) {
2918 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002919 getService().clearGrantedUriPermissions(packageName,
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002920 UserHandle.myUserId());
2921 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002922 throw e.rethrowFromSystemServer();
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002923 }
2924 }
2925
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002926 /**
2927 * Information you can retrieve about any processes that are in an error condition.
2928 */
2929 public static class ProcessErrorStateInfo implements Parcelable {
2930 /**
2931 * Condition codes
2932 */
2933 public static final int NO_ERROR = 0;
2934 public static final int CRASHED = 1;
2935 public static final int NOT_RESPONDING = 2;
2936
2937 /**
2938 * The condition that the process is in.
2939 */
2940 public int condition;
2941
2942 /**
2943 * The process name in which the crash or error occurred.
2944 */
2945 public String processName;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002947 /**
2948 * The pid of this process; 0 if none
2949 */
2950 public int pid;
2951
2952 /**
2953 * The kernel user-ID that has been assigned to this process;
2954 * currently this is not a unique ID (multiple applications can have
2955 * the same uid).
2956 */
2957 public int uid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002958
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002959 /**
Dan Egnor60d87622009-12-16 16:32:58 -08002960 * The activity name associated with the error, if known. May be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002961 */
2962 public String tag;
2963
2964 /**
2965 * A short message describing the error condition.
2966 */
2967 public String shortMsg;
2968
2969 /**
2970 * A long message describing the error condition.
2971 */
2972 public String longMsg;
2973
2974 /**
Dan Egnorb7f03672009-12-09 16:22:32 -08002975 * The stack trace where the error originated. May be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002976 */
Dan Egnorb7f03672009-12-09 16:22:32 -08002977 public String stackTrace;
2978
2979 /**
2980 * to be deprecated: This value will always be null.
2981 */
2982 public byte[] crashData = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002983
2984 public ProcessErrorStateInfo() {
2985 }
2986
Craig Mautner5ff12102013-05-24 12:50:15 -07002987 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002988 public int describeContents() {
2989 return 0;
2990 }
2991
Craig Mautner5ff12102013-05-24 12:50:15 -07002992 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002993 public void writeToParcel(Parcel dest, int flags) {
2994 dest.writeInt(condition);
2995 dest.writeString(processName);
2996 dest.writeInt(pid);
2997 dest.writeInt(uid);
2998 dest.writeString(tag);
2999 dest.writeString(shortMsg);
3000 dest.writeString(longMsg);
Dan Egnorb7f03672009-12-09 16:22:32 -08003001 dest.writeString(stackTrace);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003002 }
Craig Mautner5ff12102013-05-24 12:50:15 -07003003
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003004 public void readFromParcel(Parcel source) {
3005 condition = source.readInt();
3006 processName = source.readString();
3007 pid = source.readInt();
3008 uid = source.readInt();
3009 tag = source.readString();
3010 shortMsg = source.readString();
3011 longMsg = source.readString();
Dan Egnorb7f03672009-12-09 16:22:32 -08003012 stackTrace = source.readString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003013 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07003014
3015 public static final Creator<ProcessErrorStateInfo> CREATOR =
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003016 new Creator<ProcessErrorStateInfo>() {
3017 public ProcessErrorStateInfo createFromParcel(Parcel source) {
3018 return new ProcessErrorStateInfo(source);
3019 }
3020 public ProcessErrorStateInfo[] newArray(int size) {
3021 return new ProcessErrorStateInfo[size];
3022 }
3023 };
3024
3025 private ProcessErrorStateInfo(Parcel source) {
3026 readFromParcel(source);
3027 }
3028 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07003029
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003030 /**
Stefan Kuhne16045c22015-06-05 07:18:06 -07003031 * 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 -08003032 * will be null if all processes are running properly at this time.
Stefan Kuhne16045c22015-06-05 07:18:06 -07003033 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003034 * @return Returns a list of ProcessErrorStateInfo records, or null if there are no
3035 * current error conditions (it will not return an empty list). This list ordering is not
3036 * specified.
3037 */
3038 public List<ProcessErrorStateInfo> getProcessesInErrorState() {
3039 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003040 return getService().getProcessesInErrorState();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003041 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003042 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003043 }
3044 }
3045
3046 /**
3047 * Information you can retrieve about a running process.
3048 */
Stefan Kuhne16045c22015-06-05 07:18:06 -07003049 public static class RunningAppProcessInfo implements Parcelable {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003050 /**
3051 * The name of the process that this object is associated with
3052 */
3053 public String processName;
3054
3055 /**
3056 * The pid of this process; 0 if none
3057 */
3058 public int pid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003059
Dianne Hackborneb034652009-09-07 00:49:58 -07003060 /**
3061 * The user id of this process.
3062 */
3063 public int uid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003064
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07003065 /**
3066 * All packages that have been loaded into the process.
3067 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003068 public String pkgList[];
Stefan Kuhne16045c22015-06-05 07:18:06 -07003069
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003070 /**
Dianne Hackborn482566e2010-09-03 12:51:28 -07003071 * Constant for {@link #flags}: this is an app that is unable to
3072 * correctly save its state when going to the background,
3073 * so it can not be killed while in the background.
3074 * @hide
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07003075 */
Dianne Hackborn482566e2010-09-03 12:51:28 -07003076 public static final int FLAG_CANT_SAVE_STATE = 1<<0;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003077
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07003078 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07003079 * Constant for {@link #flags}: this process is associated with a
3080 * persistent system app.
3081 * @hide
3082 */
3083 public static final int FLAG_PERSISTENT = 1<<1;
3084
3085 /**
Dianne Hackborn0c380492012-08-20 17:23:30 -07003086 * Constant for {@link #flags}: this process is associated with a
3087 * persistent system app.
3088 * @hide
3089 */
3090 public static final int FLAG_HAS_ACTIVITIES = 1<<2;
3091
3092 /**
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07003093 * Flags of information. May be any of
Dianne Hackborn482566e2010-09-03 12:51:28 -07003094 * {@link #FLAG_CANT_SAVE_STATE}.
3095 * @hide
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07003096 */
3097 public int flags;
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003098
3099 /**
3100 * Last memory trim level reported to the process: corresponds to
3101 * the values supplied to {@link android.content.ComponentCallbacks2#onTrimMemory(int)
3102 * ComponentCallbacks2.onTrimMemory(int)}.
3103 */
3104 public int lastTrimLevel;
3105
Jeff Sharkey910e0812017-04-21 16:29:27 -06003106 /** @hide */
3107 @IntDef(prefix = { "IMPORTANCE_" }, value = {
3108 IMPORTANCE_FOREGROUND,
3109 IMPORTANCE_FOREGROUND_SERVICE,
3110 IMPORTANCE_TOP_SLEEPING,
3111 IMPORTANCE_VISIBLE,
3112 IMPORTANCE_PERCEPTIBLE,
3113 IMPORTANCE_CANT_SAVE_STATE,
3114 IMPORTANCE_SERVICE,
3115 IMPORTANCE_CACHED,
3116 IMPORTANCE_GONE,
3117 })
3118 @Retention(RetentionPolicy.SOURCE)
3119 public @interface Importance {}
3120
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07003121 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07003122 * Constant for {@link #importance}: This process is running the
3123 * foreground UI; that is, it is the thing currently at the top of the screen
3124 * that the user is interacting with.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003125 */
3126 public static final int IMPORTANCE_FOREGROUND = 100;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003127
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003128 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07003129 * Constant for {@link #importance}: This process is running a foreground
3130 * service, for example to perform music playback even while the user is
3131 * not immediately in the app. This generally indicates that the process
3132 * is doing something the user actively cares about.
3133 */
3134 public static final int IMPORTANCE_FOREGROUND_SERVICE = 125;
3135
3136 /**
3137 * Constant for {@link #importance}: This process is running the foreground
3138 * UI, but the device is asleep so it is not visible to the user. This means
3139 * the user is not really aware of the process, because they can not see or
3140 * interact with it, but it is quite important because it what they expect to
3141 * return to once unlocking the device.
3142 */
3143 public static final int IMPORTANCE_TOP_SLEEPING = 150;
3144
3145 /**
3146 * Constant for {@link #importance}: This process is running something
Dianne Hackborn32907cf2010-06-10 17:50:20 -07003147 * that is actively visible to the user, though not in the immediate
Dianne Hackborn1e383822015-04-10 14:02:33 -07003148 * foreground. This may be running a window that is behind the current
3149 * foreground (so paused and with its state saved, not interacting with
3150 * the user, but visible to them to some degree); it may also be running
3151 * other services under the system's control that it inconsiders important.
Dianne Hackborn860755f2010-06-03 18:47:52 -07003152 */
Dianne Hackborn32907cf2010-06-10 17:50:20 -07003153 public static final int IMPORTANCE_VISIBLE = 200;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003154
Dianne Hackborn860755f2010-06-03 18:47:52 -07003155 /**
Makoto Onukid7e40582017-04-13 14:54:56 -07003156 * Constant for {@link #importance}: {@link #IMPORTANCE_PERCEPTIBLE} had this wrong value
3157 * before {@link Build.VERSION_CODES#O}. Since the {@link Build.VERSION_CODES#O} SDK,
3158 * the value of {@link #IMPORTANCE_PERCEPTIBLE} has been fixed.
3159 *
Makoto Onukie92f7942017-04-26 14:38:18 -07003160 * <p>The system will return this value instead of {@link #IMPORTANCE_PERCEPTIBLE}
3161 * on Android versions below {@link Build.VERSION_CODES#O}.
3162 *
3163 * <p>On Android version {@link Build.VERSION_CODES#O} and later, this value will still be
3164 * returned for apps with the target API level below {@link Build.VERSION_CODES#O}.
3165 * For apps targeting version {@link Build.VERSION_CODES#O} and later,
3166 * the correct value {@link #IMPORTANCE_PERCEPTIBLE} will be returned.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003167 */
Makoto Onukie92f7942017-04-26 14:38:18 -07003168 public static final int IMPORTANCE_PERCEPTIBLE_PRE_26 = 130;
Makoto Onukid7e40582017-04-13 14:54:56 -07003169
3170 /**
3171 * Constant for {@link #importance}: This process is not something the user
3172 * is directly aware of, but is otherwise perceptible to them to some degree.
3173 */
3174 public static final int IMPORTANCE_PERCEPTIBLE = 230;
3175
3176 /**
3177 * Constant for {@link #importance}: {@link #IMPORTANCE_CANT_SAVE_STATE} had
3178 * this wrong value
3179 * before {@link Build.VERSION_CODES#O}. Since the {@link Build.VERSION_CODES#O} SDK,
3180 * the value of {@link #IMPORTANCE_CANT_SAVE_STATE} has been fixed.
3181 *
Makoto Onukie92f7942017-04-26 14:38:18 -07003182 * <p>The system will return this value instead of {@link #IMPORTANCE_CANT_SAVE_STATE}
3183 * on Android versions below {@link Build.VERSION_CODES#O}.
3184 *
3185 * <p>On Android version {@link Build.VERSION_CODES#O} after, this value will still be
3186 * returned for apps with the target API level below {@link Build.VERSION_CODES#O}.
3187 * For apps targeting version {@link Build.VERSION_CODES#O} and later,
3188 * the correct value {@link #IMPORTANCE_CANT_SAVE_STATE} will be returned.
3189 *
Makoto Onukid7e40582017-04-13 14:54:56 -07003190 * @hide
3191 */
Makoto Onukie92f7942017-04-26 14:38:18 -07003192 public static final int IMPORTANCE_CANT_SAVE_STATE_PRE_26 = 170;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003193
Dianne Hackborn32907cf2010-06-10 17:50:20 -07003194 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07003195 * Constant for {@link #importance}: This process is running an
Dianne Hackborn5383f502010-10-22 12:59:20 -07003196 * application that can not save its state, and thus can't be killed
3197 * while in the background.
3198 * @hide
Dianne Hackborn32907cf2010-06-10 17:50:20 -07003199 */
Makoto Onukid7e40582017-04-13 14:54:56 -07003200 public static final int IMPORTANCE_CANT_SAVE_STATE= 270;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003201
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003202 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07003203 * Constant for {@link #importance}: This process is contains services
3204 * that should remain running. These are background services apps have
3205 * started, not something the user is aware of, so they may be killed by
3206 * the system relatively freely (though it is generally desired that they
3207 * stay running as long as they want to).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003208 */
3209 public static final int IMPORTANCE_SERVICE = 300;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003210
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003211 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07003212 * Constant for {@link #importance}: This process process contains
Dianne Hackborn45e69d62017-03-01 16:02:15 -08003213 * cached code that is expendable, not actively running any app components
3214 * we care about.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003215 */
Dianne Hackborn45e69d62017-03-01 16:02:15 -08003216 public static final int IMPORTANCE_CACHED = 400;
3217
3218 /**
3219 * @deprecated Renamed to {@link #IMPORTANCE_CACHED}.
3220 */
3221 public static final int IMPORTANCE_BACKGROUND = IMPORTANCE_CACHED;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003222
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003223 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07003224 * Constant for {@link #importance}: This process is empty of any
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003225 * actively running code.
Dianne Hackborn45e69d62017-03-01 16:02:15 -08003226 * @deprecated This value is no longer reported, use {@link #IMPORTANCE_CACHED} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003227 */
Dianne Hackborn45e69d62017-03-01 16:02:15 -08003228 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003229 public static final int IMPORTANCE_EMPTY = 500;
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003230
3231 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07003232 * Constant for {@link #importance}: This process does not exist.
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003233 */
3234 public static final int IMPORTANCE_GONE = 1000;
3235
Makoto Onukid7e40582017-04-13 14:54:56 -07003236 /**
3237 * Convert a proc state to the correspondent IMPORTANCE_* constant. If the return value
3238 * will be passed to a client, use {@link #procStateToImportanceForClient}.
3239 * @hide
3240 */
Jeff Sharkey910e0812017-04-21 16:29:27 -06003241 public static @Importance int procStateToImportance(int procState) {
Dianne Hackborn1e383822015-04-10 14:02:33 -07003242 if (procState == PROCESS_STATE_NONEXISTENT) {
3243 return IMPORTANCE_GONE;
3244 } else if (procState >= PROCESS_STATE_HOME) {
Dianne Hackborn45e69d62017-03-01 16:02:15 -08003245 return IMPORTANCE_CACHED;
Dianne Hackborn1e383822015-04-10 14:02:33 -07003246 } else if (procState >= PROCESS_STATE_SERVICE) {
3247 return IMPORTANCE_SERVICE;
3248 } else if (procState > PROCESS_STATE_HEAVY_WEIGHT) {
3249 return IMPORTANCE_CANT_SAVE_STATE;
Dianne Hackborn83b40f62017-04-26 13:59:47 -07003250 } else if (procState >= PROCESS_STATE_TRANSIENT_BACKGROUND) {
Dianne Hackborn1e383822015-04-10 14:02:33 -07003251 return IMPORTANCE_PERCEPTIBLE;
3252 } else if (procState >= PROCESS_STATE_IMPORTANT_FOREGROUND) {
3253 return IMPORTANCE_VISIBLE;
3254 } else if (procState >= PROCESS_STATE_TOP_SLEEPING) {
3255 return IMPORTANCE_TOP_SLEEPING;
3256 } else if (procState >= PROCESS_STATE_FOREGROUND_SERVICE) {
3257 return IMPORTANCE_FOREGROUND_SERVICE;
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003258 } else {
Dianne Hackborn1e383822015-04-10 14:02:33 -07003259 return IMPORTANCE_FOREGROUND;
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003260 }
3261 }
3262
Makoto Onukid7e40582017-04-13 14:54:56 -07003263 /**
3264 * Convert a proc state to the correspondent IMPORTANCE_* constant for a client represented
3265 * by a given {@link Context}, with converting {@link #IMPORTANCE_PERCEPTIBLE}
3266 * and {@link #IMPORTANCE_CANT_SAVE_STATE} to the corresponding "wrong" value if the
3267 * client's target SDK < {@link VERSION_CODES#O}.
3268 * @hide
3269 */
Jeff Sharkey910e0812017-04-21 16:29:27 -06003270 public static @Importance int procStateToImportanceForClient(int procState,
3271 Context clientContext) {
Makoto Onukie92f7942017-04-26 14:38:18 -07003272 return procStateToImportanceForTargetSdk(procState,
3273 clientContext.getApplicationInfo().targetSdkVersion);
3274 }
3275
3276 /**
3277 * See {@link #procStateToImportanceForClient}.
3278 * @hide
3279 */
3280 public static @Importance int procStateToImportanceForTargetSdk(int procState,
3281 int targetSdkVersion) {
Makoto Onukid7e40582017-04-13 14:54:56 -07003282 final int importance = procStateToImportance(procState);
3283
3284 // For pre O apps, convert to the old, wrong values.
Makoto Onukie92f7942017-04-26 14:38:18 -07003285 if (targetSdkVersion < VERSION_CODES.O) {
Makoto Onukid7e40582017-04-13 14:54:56 -07003286 switch (importance) {
3287 case IMPORTANCE_PERCEPTIBLE:
Makoto Onukie92f7942017-04-26 14:38:18 -07003288 return IMPORTANCE_PERCEPTIBLE_PRE_26;
Makoto Onukid7e40582017-04-13 14:54:56 -07003289 case IMPORTANCE_CANT_SAVE_STATE:
Makoto Onukie92f7942017-04-26 14:38:18 -07003290 return IMPORTANCE_CANT_SAVE_STATE_PRE_26;
Makoto Onukid7e40582017-04-13 14:54:56 -07003291 }
3292 }
3293 return importance;
3294 }
3295
Dianne Hackborn5614bf52016-11-07 17:26:41 -08003296 /** @hide */
Jeff Sharkey910e0812017-04-21 16:29:27 -06003297 public static int importanceToProcState(@Importance int importance) {
Dianne Hackborn5614bf52016-11-07 17:26:41 -08003298 if (importance == IMPORTANCE_GONE) {
3299 return PROCESS_STATE_NONEXISTENT;
Dianne Hackborn45e69d62017-03-01 16:02:15 -08003300 } else if (importance >= IMPORTANCE_CACHED) {
Dianne Hackborn5614bf52016-11-07 17:26:41 -08003301 return PROCESS_STATE_HOME;
3302 } else if (importance >= IMPORTANCE_SERVICE) {
3303 return PROCESS_STATE_SERVICE;
3304 } else if (importance > IMPORTANCE_CANT_SAVE_STATE) {
3305 return PROCESS_STATE_HEAVY_WEIGHT;
3306 } else if (importance >= IMPORTANCE_PERCEPTIBLE) {
Dianne Hackborn83b40f62017-04-26 13:59:47 -07003307 return PROCESS_STATE_TRANSIENT_BACKGROUND;
Dianne Hackborn5614bf52016-11-07 17:26:41 -08003308 } else if (importance >= IMPORTANCE_VISIBLE) {
3309 return PROCESS_STATE_IMPORTANT_FOREGROUND;
3310 } else if (importance >= IMPORTANCE_TOP_SLEEPING) {
3311 return PROCESS_STATE_TOP_SLEEPING;
3312 } else if (importance >= IMPORTANCE_FOREGROUND_SERVICE) {
3313 return PROCESS_STATE_FOREGROUND_SERVICE;
3314 } else {
3315 return PROCESS_STATE_BOUND_FOREGROUND_SERVICE;
3316 }
3317 }
3318
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003319 /**
Jeff Sharkey910e0812017-04-21 16:29:27 -06003320 * The relative importance level that the system places on this process.
3321 * These constants are numbered so that "more important" values are
3322 * always smaller than "less important" values.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003323 */
Jeff Sharkey910e0812017-04-21 16:29:27 -06003324 public @Importance int importance;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003325
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003326 /**
3327 * An additional ordering within a particular {@link #importance}
3328 * category, providing finer-grained information about the relative
3329 * utility of processes within a category. This number means nothing
3330 * except that a smaller values are more recently used (and thus
3331 * more important). Currently an LRU value is only maintained for
Dianne Hackborn45e69d62017-03-01 16:02:15 -08003332 * the {@link #IMPORTANCE_CACHED} category, though others may
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003333 * be maintained in the future.
3334 */
3335 public int lru;
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003336
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003337 /**
3338 * Constant for {@link #importanceReasonCode}: nothing special has
3339 * been specified for the reason for this level.
3340 */
3341 public static final int REASON_UNKNOWN = 0;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003342
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003343 /**
3344 * Constant for {@link #importanceReasonCode}: one of the application's
3345 * content providers is being used by another process. The pid of
3346 * the client process is in {@link #importanceReasonPid} and the
3347 * target provider in this process is in
3348 * {@link #importanceReasonComponent}.
3349 */
3350 public static final int REASON_PROVIDER_IN_USE = 1;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003351
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003352 /**
3353 * Constant for {@link #importanceReasonCode}: one of the application's
3354 * content providers is being used by another process. The pid of
3355 * the client process is in {@link #importanceReasonPid} and the
3356 * target provider in this process is in
3357 * {@link #importanceReasonComponent}.
3358 */
3359 public static final int REASON_SERVICE_IN_USE = 2;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003360
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003361 /**
3362 * The reason for {@link #importance}, if any.
3363 */
3364 public int importanceReasonCode;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003365
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003366 /**
3367 * For the specified values of {@link #importanceReasonCode}, this
3368 * is the process ID of the other process that is a client of this
3369 * process. This will be 0 if no other process is using this one.
3370 */
3371 public int importanceReasonPid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003372
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003373 /**
3374 * For the specified values of {@link #importanceReasonCode}, this
3375 * is the name of the component that is being used in this process.
3376 */
3377 public ComponentName importanceReasonComponent;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003378
Dianne Hackborn905577f2011-09-07 18:31:28 -07003379 /**
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003380 * When {@link #importanceReasonPid} is non-0, this is the importance
Dianne Hackborn905577f2011-09-07 18:31:28 -07003381 * of the other pid. @hide
3382 */
3383 public int importanceReasonImportance;
3384
Dianne Hackborn684bf342014-04-29 17:56:57 -07003385 /**
3386 * Current process state, as per PROCESS_STATE_* constants.
3387 * @hide
3388 */
3389 public int processState;
3390
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003391 public RunningAppProcessInfo() {
3392 importance = IMPORTANCE_FOREGROUND;
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003393 importanceReasonCode = REASON_UNKNOWN;
Dianne Hackborn684bf342014-04-29 17:56:57 -07003394 processState = PROCESS_STATE_IMPORTANT_FOREGROUND;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003395 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07003396
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003397 public RunningAppProcessInfo(String pProcessName, int pPid, String pArr[]) {
3398 processName = pProcessName;
3399 pid = pPid;
3400 pkgList = pArr;
3401 }
3402
3403 public int describeContents() {
3404 return 0;
3405 }
3406
3407 public void writeToParcel(Parcel dest, int flags) {
3408 dest.writeString(processName);
3409 dest.writeInt(pid);
Dianne Hackborneb034652009-09-07 00:49:58 -07003410 dest.writeInt(uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003411 dest.writeStringArray(pkgList);
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07003412 dest.writeInt(this.flags);
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003413 dest.writeInt(lastTrimLevel);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003414 dest.writeInt(importance);
3415 dest.writeInt(lru);
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003416 dest.writeInt(importanceReasonCode);
3417 dest.writeInt(importanceReasonPid);
3418 ComponentName.writeToParcel(importanceReasonComponent, dest);
Dianne Hackborn905577f2011-09-07 18:31:28 -07003419 dest.writeInt(importanceReasonImportance);
Dianne Hackborn684bf342014-04-29 17:56:57 -07003420 dest.writeInt(processState);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003421 }
3422
3423 public void readFromParcel(Parcel source) {
3424 processName = source.readString();
3425 pid = source.readInt();
Dianne Hackborneb034652009-09-07 00:49:58 -07003426 uid = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003427 pkgList = source.readStringArray();
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07003428 flags = source.readInt();
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003429 lastTrimLevel = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003430 importance = source.readInt();
3431 lru = source.readInt();
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003432 importanceReasonCode = source.readInt();
3433 importanceReasonPid = source.readInt();
3434 importanceReasonComponent = ComponentName.readFromParcel(source);
Dianne Hackborn905577f2011-09-07 18:31:28 -07003435 importanceReasonImportance = source.readInt();
Dianne Hackborn684bf342014-04-29 17:56:57 -07003436 processState = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003437 }
3438
Stefan Kuhne16045c22015-06-05 07:18:06 -07003439 public static final Creator<RunningAppProcessInfo> CREATOR =
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003440 new Creator<RunningAppProcessInfo>() {
3441 public RunningAppProcessInfo createFromParcel(Parcel source) {
3442 return new RunningAppProcessInfo(source);
3443 }
3444 public RunningAppProcessInfo[] newArray(int size) {
3445 return new RunningAppProcessInfo[size];
3446 }
3447 };
3448
3449 private RunningAppProcessInfo(Parcel source) {
3450 readFromParcel(source);
3451 }
3452 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07003453
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003454 /**
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -07003455 * Returns a list of application processes installed on external media
3456 * that are running on the device.
3457 *
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07003458 * <p><b>Note: this method is only intended for debugging or building
3459 * a user-facing process management UI.</b></p>
3460 *
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -07003461 * @return Returns a list of ApplicationInfo records, or null if none
3462 * This list ordering is not specified.
3463 * @hide
3464 */
3465 public List<ApplicationInfo> getRunningExternalApplications() {
3466 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003467 return getService().getRunningExternalApplications();
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -07003468 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003469 throw e.rethrowFromSystemServer();
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -07003470 }
3471 }
3472
3473 /**
Stefan Kuhne16045c22015-06-05 07:18:06 -07003474 * Sets the memory trim mode for a process and schedules a memory trim operation.
3475 *
3476 * <p><b>Note: this method is only intended for testing framework.</b></p>
3477 *
3478 * @return Returns true if successful.
3479 * @hide
3480 */
3481 public boolean setProcessMemoryTrimLevel(String process, int userId, int level) {
3482 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003483 return getService().setProcessMemoryTrimLevel(process, userId,
Stefan Kuhne16045c22015-06-05 07:18:06 -07003484 level);
3485 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003486 throw e.rethrowFromSystemServer();
Stefan Kuhne16045c22015-06-05 07:18:06 -07003487 }
3488 }
3489
3490 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003491 * Returns a list of application processes that are running on the device.
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07003492 *
3493 * <p><b>Note: this method is only intended for debugging or building
3494 * a user-facing process management UI.</b></p>
3495 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003496 * @return Returns a list of RunningAppProcessInfo records, or null if there are no
3497 * running processes (it will not return an empty list). This list ordering is not
3498 * specified.
3499 */
3500 public List<RunningAppProcessInfo> getRunningAppProcesses() {
3501 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003502 return getService().getRunningAppProcesses();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003503 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003504 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003505 }
3506 }
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003507
3508 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07003509 * Return the importance of a given package name, based on the processes that are
3510 * currently running. The return value is one of the importance constants defined
3511 * in {@link RunningAppProcessInfo}, giving you the highest importance of all the
3512 * processes that this package has code running inside of. If there are no processes
3513 * running its code, {@link RunningAppProcessInfo#IMPORTANCE_GONE} is returned.
Jeff Sharkeyf85ac772015-05-13 12:52:06 -07003514 * @hide
Dianne Hackborn1e383822015-04-10 14:02:33 -07003515 */
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003516 @SystemApi @TestApi
Dianne Hackborn9df8f512016-10-24 17:58:30 -07003517 @RequiresPermission(Manifest.permission.PACKAGE_USAGE_STATS)
Jeff Sharkey910e0812017-04-21 16:29:27 -06003518 public @RunningAppProcessInfo.Importance int getPackageImportance(String packageName) {
Dianne Hackborn1e383822015-04-10 14:02:33 -07003519 try {
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003520 int procState = getService().getPackageProcessState(packageName,
Adam Lesinskic30454c2015-06-24 13:24:35 -07003521 mContext.getOpPackageName());
Makoto Onukid7e40582017-04-13 14:54:56 -07003522 return RunningAppProcessInfo.procStateToImportanceForClient(procState, mContext);
Dianne Hackborn1e383822015-04-10 14:02:33 -07003523 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003524 throw e.rethrowFromSystemServer();
Dianne Hackborn1e383822015-04-10 14:02:33 -07003525 }
3526 }
3527
3528 /**
Dianne Hackborn83249ec2017-04-12 10:54:03 -07003529 * Return the importance of a given uid, based on the processes that are
3530 * currently running. The return value is one of the importance constants defined
3531 * in {@link RunningAppProcessInfo}, giving you the highest importance of all the
3532 * processes that this uid has running. If there are no processes
3533 * running its code, {@link RunningAppProcessInfo#IMPORTANCE_GONE} is returned.
3534 * @hide
3535 */
3536 @SystemApi @TestApi
3537 @RequiresPermission(Manifest.permission.PACKAGE_USAGE_STATS)
Jeff Sharkey910e0812017-04-21 16:29:27 -06003538 public @RunningAppProcessInfo.Importance int getUidImportance(int uid) {
Dianne Hackborn83249ec2017-04-12 10:54:03 -07003539 try {
3540 int procState = getService().getUidProcessState(uid,
3541 mContext.getOpPackageName());
Makoto Onukid7e40582017-04-13 14:54:56 -07003542 return RunningAppProcessInfo.procStateToImportanceForClient(procState, mContext);
Dianne Hackborn83249ec2017-04-12 10:54:03 -07003543 } catch (RemoteException e) {
3544 throw e.rethrowFromSystemServer();
3545 }
3546 }
3547
3548 /**
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003549 * Callback to get reports about changes to the importance of a uid. Use with
3550 * {@link #addOnUidImportanceListener}.
3551 * @hide
3552 */
3553 @SystemApi @TestApi
3554 public interface OnUidImportanceListener {
3555 /**
3556 * The importance if a given uid has changed. Will be one of the importance
3557 * values in {@link RunningAppProcessInfo};
3558 * {@link RunningAppProcessInfo#IMPORTANCE_GONE IMPORTANCE_GONE} will be reported
3559 * when the uid is no longer running at all. This callback will happen on a thread
3560 * from a thread pool, not the main UI thread.
3561 * @param uid The uid whose importance has changed.
3562 * @param importance The new importance value as per {@link RunningAppProcessInfo}.
3563 */
Jeff Sharkey910e0812017-04-21 16:29:27 -06003564 void onUidImportance(int uid, @RunningAppProcessInfo.Importance int importance);
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003565 }
3566
3567 /**
3568 * Start monitoring changes to the imoportance of uids running in the system.
3569 * @param listener The listener callback that will receive change reports.
3570 * @param importanceCutpoint The level of importance in which the caller is interested
3571 * in differences. For example, if {@link RunningAppProcessInfo#IMPORTANCE_PERCEPTIBLE}
3572 * is used here, you will receive a call each time a uids importance transitions between
3573 * being <= {@link RunningAppProcessInfo#IMPORTANCE_PERCEPTIBLE} and
3574 * > {@link RunningAppProcessInfo#IMPORTANCE_PERCEPTIBLE}.
3575 *
3576 * <p>The caller must hold the {@link android.Manifest.permission#PACKAGE_USAGE_STATS}
3577 * permission to use this feature.</p>
3578 *
3579 * @throws IllegalArgumentException If the listener is already registered.
3580 * @throws SecurityException If the caller does not hold
3581 * {@link android.Manifest.permission#PACKAGE_USAGE_STATS}.
3582 * @hide
3583 */
3584 @SystemApi @TestApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06003585 @RequiresPermission(Manifest.permission.PACKAGE_USAGE_STATS)
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003586 public void addOnUidImportanceListener(OnUidImportanceListener listener,
Jeff Sharkey910e0812017-04-21 16:29:27 -06003587 @RunningAppProcessInfo.Importance int importanceCutpoint) {
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003588 synchronized (this) {
3589 if (mImportanceListeners.containsKey(listener)) {
3590 throw new IllegalArgumentException("Listener already registered: " + listener);
3591 }
3592 // TODO: implement the cut point in the system process to avoid IPCs.
Makoto Onukid7e40582017-04-13 14:54:56 -07003593 UidObserver observer = new UidObserver(listener, mContext);
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003594 try {
3595 getService().registerUidObserver(observer,
Dianne Hackborn5614bf52016-11-07 17:26:41 -08003596 UID_OBSERVER_PROCSTATE | UID_OBSERVER_GONE,
3597 RunningAppProcessInfo.importanceToProcState(importanceCutpoint),
3598 mContext.getOpPackageName());
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003599 } catch (RemoteException e) {
3600 throw e.rethrowFromSystemServer();
3601 }
3602 mImportanceListeners.put(listener, observer);
3603 }
3604 }
3605
3606 /**
3607 * Remove an importance listener that was previously registered with
3608 * {@link #addOnUidImportanceListener}.
3609 *
3610 * @throws IllegalArgumentException If the listener is not registered.
3611 * @hide
3612 */
3613 @SystemApi @TestApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06003614 @RequiresPermission(Manifest.permission.PACKAGE_USAGE_STATS)
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003615 public void removeOnUidImportanceListener(OnUidImportanceListener listener) {
3616 synchronized (this) {
3617 UidObserver observer = mImportanceListeners.remove(listener);
3618 if (observer == null) {
3619 throw new IllegalArgumentException("Listener not registered: " + listener);
3620 }
3621 try {
3622 getService().unregisterUidObserver(observer);
3623 } catch (RemoteException e) {
3624 throw e.rethrowFromSystemServer();
3625 }
3626 }
3627 }
3628
3629 /**
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003630 * Return global memory state information for the calling process. This
3631 * does not fill in all fields of the {@link RunningAppProcessInfo}. The
3632 * only fields that will be filled in are
3633 * {@link RunningAppProcessInfo#pid},
3634 * {@link RunningAppProcessInfo#uid},
3635 * {@link RunningAppProcessInfo#lastTrimLevel},
3636 * {@link RunningAppProcessInfo#importance},
3637 * {@link RunningAppProcessInfo#lru}, and
3638 * {@link RunningAppProcessInfo#importanceReasonCode}.
3639 */
3640 static public void getMyMemoryState(RunningAppProcessInfo outState) {
3641 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003642 getService().getMyMemoryState(outState);
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003643 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003644 throw e.rethrowFromSystemServer();
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003645 }
3646 }
3647
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003648 /**
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07003649 * Return information about the memory usage of one or more processes.
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07003650 *
3651 * <p><b>Note: this method is only intended for debugging or building
3652 * a user-facing process management UI.</b></p>
3653 *
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07003654 * @param pids The pids of the processes whose memory usage is to be
3655 * retrieved.
3656 * @return Returns an array of memory information, one for each
3657 * requested pid.
3658 */
3659 public Debug.MemoryInfo[] getProcessMemoryInfo(int[] pids) {
3660 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003661 return getService().getProcessMemoryInfo(pids);
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07003662 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003663 throw e.rethrowFromSystemServer();
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07003664 }
3665 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07003666
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07003667 /**
Dianne Hackborn03abb812010-01-04 18:43:19 -08003668 * @deprecated This is now just a wrapper for
3669 * {@link #killBackgroundProcesses(String)}; the previous behavior here
3670 * is no longer available to applications because it allows them to
3671 * break other applications by removing their alarms, stopping their
3672 * services, etc.
3673 */
3674 @Deprecated
3675 public void restartPackage(String packageName) {
3676 killBackgroundProcesses(packageName);
3677 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07003678
Dianne Hackborn03abb812010-01-04 18:43:19 -08003679 /**
3680 * Have the system immediately kill all background processes associated
3681 * with the given package. This is the same as the kernel killing those
3682 * processes to reclaim memory; the system will take care of restarting
3683 * these processes in the future as needed.
Stefan Kuhne16045c22015-06-05 07:18:06 -07003684 *
Dianne Hackborn03abb812010-01-04 18:43:19 -08003685 * @param packageName The name of the package whose processes are to
3686 * be killed.
3687 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003688 @RequiresPermission(Manifest.permission.KILL_BACKGROUND_PROCESSES)
Dianne Hackborn03abb812010-01-04 18:43:19 -08003689 public void killBackgroundProcesses(String packageName) {
3690 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003691 getService().killBackgroundProcesses(packageName,
Dianne Hackborn1676c852012-09-10 14:52:30 -07003692 UserHandle.myUserId());
Dianne Hackborn03abb812010-01-04 18:43:19 -08003693 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003694 throw e.rethrowFromSystemServer();
Dianne Hackborn03abb812010-01-04 18:43:19 -08003695 }
3696 }
Svet Ganov019d2302015-05-04 11:07:38 -07003697
3698 /**
3699 * Kills the specified UID.
3700 * @param uid The UID to kill.
3701 * @param reason The reason for the kill.
3702 *
3703 * @hide
3704 */
Svet Ganovae0e03a2016-02-25 18:22:10 -08003705 @SystemApi
Svet Ganov019d2302015-05-04 11:07:38 -07003706 @RequiresPermission(Manifest.permission.KILL_UID)
3707 public void killUid(int uid, String reason) {
3708 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003709 getService().killUid(UserHandle.getAppId(uid),
Svetoslavaa41add2015-08-06 15:03:55 -07003710 UserHandle.getUserId(uid), reason);
Svet Ganov019d2302015-05-04 11:07:38 -07003711 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003712 throw e.rethrowFromSystemServer();
Svet Ganov019d2302015-05-04 11:07:38 -07003713 }
3714 }
3715
Dianne Hackborn03abb812010-01-04 18:43:19 -08003716 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003717 * Have the system perform a force stop of everything associated with
3718 * the given application package. All processes that share its uid
3719 * will be killed, all services it has running stopped, all activities
3720 * removed, etc. In addition, a {@link Intent#ACTION_PACKAGE_RESTARTED}
3721 * broadcast will be sent, so that any of its registered alarms can
3722 * be stopped, notifications removed, etc.
Stefan Kuhne16045c22015-06-05 07:18:06 -07003723 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003724 * <p>You must hold the permission
Dianne Hackborn03abb812010-01-04 18:43:19 -08003725 * {@link android.Manifest.permission#FORCE_STOP_PACKAGES} to be able to
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003726 * call this method.
Stefan Kuhne16045c22015-06-05 07:18:06 -07003727 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003728 * @param packageName The name of the package to be stopped.
Zoltan Szatmary-Ban0bec95d2014-09-23 17:27:17 +01003729 * @param userId The user for which the running package is to be stopped.
Stefan Kuhne16045c22015-06-05 07:18:06 -07003730 *
Dianne Hackborn03abb812010-01-04 18:43:19 -08003731 * @hide This is not available to third party applications due to
3732 * it allowing them to break other applications by stopping their
3733 * services, removing their alarms, etc.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003734 */
Zoltan Szatmary-Ban0bec95d2014-09-23 17:27:17 +01003735 public void forceStopPackageAsUser(String packageName, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003736 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003737 getService().forceStopPackage(packageName, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003738 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003739 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003740 }
3741 }
Zoltan Szatmary-Ban0bec95d2014-09-23 17:27:17 +01003742
3743 /**
3744 * @see #forceStopPackageAsUser(String, int)
3745 * @hide
3746 */
Jeff Schumacherb8cadef2017-01-03 13:52:48 -08003747 @SystemApi
3748 @RequiresPermission(Manifest.permission.FORCE_STOP_PACKAGES)
Zoltan Szatmary-Ban0bec95d2014-09-23 17:27:17 +01003749 public void forceStopPackage(String packageName) {
3750 forceStopPackageAsUser(packageName, UserHandle.myUserId());
3751 }
3752
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003753 /**
3754 * Get the device configuration attributes.
3755 */
3756 public ConfigurationInfo getDeviceConfigurationInfo() {
3757 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003758 return getService().getDeviceConfigurationInfo();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003759 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003760 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003761 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003762 }
Kenny Root5ef44b72011-01-26 17:22:20 -08003763
3764 /**
3765 * Get the preferred density of icons for the launcher. This is used when
3766 * custom drawables are created (e.g., for shortcuts).
3767 *
3768 * @return density in terms of DPI
3769 */
3770 public int getLauncherLargeIconDensity() {
3771 final Resources res = mContext.getResources();
3772 final int density = res.getDisplayMetrics().densityDpi;
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003773 final int sw = res.getConfiguration().smallestScreenWidthDp;
Kenny Root5ef44b72011-01-26 17:22:20 -08003774
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003775 if (sw < 600) {
3776 // Smaller than approx 7" tablets, use the regular icon size.
Kenny Root5ef44b72011-01-26 17:22:20 -08003777 return density;
3778 }
3779
3780 switch (density) {
3781 case DisplayMetrics.DENSITY_LOW:
3782 return DisplayMetrics.DENSITY_MEDIUM;
3783 case DisplayMetrics.DENSITY_MEDIUM:
3784 return DisplayMetrics.DENSITY_HIGH;
Dianne Hackbornd0356a12012-04-26 19:03:12 -07003785 case DisplayMetrics.DENSITY_TV:
3786 return DisplayMetrics.DENSITY_XHIGH;
Kenny Root5ef44b72011-01-26 17:22:20 -08003787 case DisplayMetrics.DENSITY_HIGH:
3788 return DisplayMetrics.DENSITY_XHIGH;
3789 case DisplayMetrics.DENSITY_XHIGH:
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003790 return DisplayMetrics.DENSITY_XXHIGH;
3791 case DisplayMetrics.DENSITY_XXHIGH:
3792 return DisplayMetrics.DENSITY_XHIGH * 2;
Kenny Root5ef44b72011-01-26 17:22:20 -08003793 default:
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003794 // The density is some abnormal value. Return some other
3795 // abnormal value that is a reasonable scaling of it.
Dianne Hackbornd0356a12012-04-26 19:03:12 -07003796 return (int)((density*1.5f)+.5f);
Kenny Root5ef44b72011-01-26 17:22:20 -08003797 }
3798 }
3799
3800 /**
3801 * Get the preferred launcher icon size. This is used when custom drawables
3802 * are created (e.g., for shortcuts).
3803 *
3804 * @return dimensions of square icons in terms of pixels
3805 */
3806 public int getLauncherLargeIconSize() {
Craig Mautner2fbd7542014-03-21 09:34:07 -07003807 return getLauncherLargeIconSizeInner(mContext);
3808 }
3809
3810 static int getLauncherLargeIconSizeInner(Context context) {
3811 final Resources res = context.getResources();
Kenny Root5ef44b72011-01-26 17:22:20 -08003812 final int size = res.getDimensionPixelSize(android.R.dimen.app_icon_size);
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003813 final int sw = res.getConfiguration().smallestScreenWidthDp;
Kenny Root5ef44b72011-01-26 17:22:20 -08003814
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003815 if (sw < 600) {
3816 // Smaller than approx 7" tablets, use the regular icon size.
Kenny Root5ef44b72011-01-26 17:22:20 -08003817 return size;
3818 }
3819
3820 final int density = res.getDisplayMetrics().densityDpi;
3821
3822 switch (density) {
3823 case DisplayMetrics.DENSITY_LOW:
3824 return (size * DisplayMetrics.DENSITY_MEDIUM) / DisplayMetrics.DENSITY_LOW;
3825 case DisplayMetrics.DENSITY_MEDIUM:
3826 return (size * DisplayMetrics.DENSITY_HIGH) / DisplayMetrics.DENSITY_MEDIUM;
Dianne Hackbornd0356a12012-04-26 19:03:12 -07003827 case DisplayMetrics.DENSITY_TV:
3828 return (size * DisplayMetrics.DENSITY_XHIGH) / DisplayMetrics.DENSITY_HIGH;
Kenny Root5ef44b72011-01-26 17:22:20 -08003829 case DisplayMetrics.DENSITY_HIGH:
3830 return (size * DisplayMetrics.DENSITY_XHIGH) / DisplayMetrics.DENSITY_HIGH;
3831 case DisplayMetrics.DENSITY_XHIGH:
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003832 return (size * DisplayMetrics.DENSITY_XXHIGH) / DisplayMetrics.DENSITY_XHIGH;
3833 case DisplayMetrics.DENSITY_XXHIGH:
3834 return (size * DisplayMetrics.DENSITY_XHIGH*2) / DisplayMetrics.DENSITY_XXHIGH;
Kenny Root5ef44b72011-01-26 17:22:20 -08003835 default:
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003836 // The density is some abnormal value. Return some other
3837 // abnormal value that is a reasonable scaling of it.
Dianne Hackbornd0356a12012-04-26 19:03:12 -07003838 return (int)((size*1.5f) + .5f);
Kenny Root5ef44b72011-01-26 17:22:20 -08003839 }
3840 }
3841
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08003842 /**
3843 * Returns "true" if the user interface is currently being messed with
3844 * by a monkey.
3845 */
3846 public static boolean isUserAMonkey() {
3847 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003848 return getService().isUserAMonkey();
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08003849 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003850 throw e.rethrowFromSystemServer();
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08003851 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08003852 }
Brett Chabot3b4fcbc2011-01-09 13:41:02 -08003853
3854 /**
3855 * Returns "true" if device is running in a test harness.
3856 */
3857 public static boolean isRunningInTestHarness() {
3858 return SystemProperties.getBoolean("ro.test_harness", false);
3859 }
Peter Visontay8d224ca2011-02-18 16:39:19 +00003860
3861 /**
3862 * Returns the launch count of each installed package.
3863 *
3864 * @hide
3865 */
Adam Lesinski0debc9a2014-07-16 19:09:13 -07003866 /*public Map<String, Integer> getAllPackageLaunchCounts() {
Peter Visontay8d224ca2011-02-18 16:39:19 +00003867 try {
3868 IUsageStats usageStatsService = IUsageStats.Stub.asInterface(
3869 ServiceManager.getService("usagestats"));
3870 if (usageStatsService == null) {
3871 return new HashMap<String, Integer>();
3872 }
3873
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003874 UsageStats.PackageStats[] allPkgUsageStats = usageStatsService.getAllPkgUsageStats(
3875 ActivityThread.currentPackageName());
Peter Visontaybfcda392011-03-02 18:53:37 +00003876 if (allPkgUsageStats == null) {
3877 return new HashMap<String, Integer>();
3878 }
3879
Peter Visontay8d224ca2011-02-18 16:39:19 +00003880 Map<String, Integer> launchCounts = new HashMap<String, Integer>();
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003881 for (UsageStats.PackageStats pkgUsageStats : allPkgUsageStats) {
3882 launchCounts.put(pkgUsageStats.getPackageName(), pkgUsageStats.getLaunchCount());
Peter Visontay8d224ca2011-02-18 16:39:19 +00003883 }
3884
3885 return launchCounts;
3886 } catch (RemoteException e) {
3887 Log.w(TAG, "Could not query launch counts", e);
3888 return new HashMap<String, Integer>();
3889 }
Adam Lesinski0debc9a2014-07-16 19:09:13 -07003890 }*/
Amith Yamasani4b2e9342011-03-31 12:38:53 -07003891
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003892 /** @hide */
3893 public static int checkComponentPermission(String permission, int uid,
3894 int owningUid, boolean exported) {
3895 // Root, system server get to do everything.
Svetoslavc6d1c342015-02-26 14:44:43 -08003896 final int appId = UserHandle.getAppId(uid);
3897 if (appId == Process.ROOT_UID || appId == Process.SYSTEM_UID) {
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003898 return PackageManager.PERMISSION_GRANTED;
3899 }
3900 // Isolated processes don't get any permissions.
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07003901 if (UserHandle.isIsolated(uid)) {
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003902 return PackageManager.PERMISSION_DENIED;
3903 }
3904 // If there is a uid that owns whatever is being accessed, it has
3905 // blanket access to it regardless of the permissions it requires.
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07003906 if (owningUid >= 0 && UserHandle.isSameApp(uid, owningUid)) {
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003907 return PackageManager.PERMISSION_GRANTED;
3908 }
3909 // If the target is not exported, then nobody else can get to it.
3910 if (!exported) {
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -07003911 /*
3912 RuntimeException here = new RuntimeException("here");
3913 here.fillInStackTrace();
3914 Slog.w(TAG, "Permission denied: checkComponentPermission() owningUid=" + owningUid,
3915 here);
3916 */
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003917 return PackageManager.PERMISSION_DENIED;
3918 }
3919 if (permission == null) {
3920 return PackageManager.PERMISSION_GRANTED;
3921 }
3922 try {
3923 return AppGlobals.getPackageManager()
3924 .checkUidPermission(permission, uid);
3925 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003926 throw e.rethrowFromSystemServer();
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003927 }
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003928 }
3929
Dianne Hackborn7d19e022012-08-07 19:12:33 -07003930 /** @hide */
3931 public static int checkUidPermission(String permission, int uid) {
3932 try {
3933 return AppGlobals.getPackageManager()
3934 .checkUidPermission(permission, uid);
3935 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003936 throw e.rethrowFromSystemServer();
Dianne Hackborn7d19e022012-08-07 19:12:33 -07003937 }
Dianne Hackborn7d19e022012-08-07 19:12:33 -07003938 }
3939
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08003940 /**
3941 * @hide
3942 * Helper for dealing with incoming user arguments to system service calls.
3943 * Takes care of checking permissions and converting USER_CURRENT to the
3944 * actual current user.
3945 *
3946 * @param callingPid The pid of the incoming call, as per Binder.getCallingPid().
3947 * @param callingUid The uid of the incoming call, as per Binder.getCallingUid().
3948 * @param userId The user id argument supplied by the caller -- this is the user
3949 * they want to run as.
3950 * @param allowAll If true, we will allow USER_ALL. This means you must be prepared
3951 * to get a USER_ALL returned and deal with it correctly. If false,
3952 * an exception will be thrown if USER_ALL is supplied.
3953 * @param requireFull If true, the caller must hold
3954 * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} to be able to run as a
3955 * different user than their current process; otherwise they must hold
3956 * {@link android.Manifest.permission#INTERACT_ACROSS_USERS}.
3957 * @param name Optional textual name of the incoming call; only for generating error messages.
3958 * @param callerPackage Optional package name of caller; only for error messages.
3959 *
3960 * @return Returns the user ID that the call should run as. Will always be a concrete
3961 * user number, unless <var>allowAll</var> is true in which case it could also be
3962 * USER_ALL.
3963 */
Dianne Hackborn41203752012-08-31 14:05:51 -07003964 public static int handleIncomingUser(int callingPid, int callingUid, int userId,
3965 boolean allowAll, boolean requireFull, String name, String callerPackage) {
3966 if (UserHandle.getUserId(callingUid) == userId) {
3967 return userId;
3968 }
3969 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003970 return getService().handleIncomingUser(callingPid,
Dianne Hackborn41203752012-08-31 14:05:51 -07003971 callingUid, userId, allowAll, requireFull, name, callerPackage);
3972 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003973 throw e.rethrowFromSystemServer();
Dianne Hackborn41203752012-08-31 14:05:51 -07003974 }
3975 }
3976
Amith Yamasani0e8d7d62014-09-03 13:17:28 -07003977 /**
3978 * Gets the userId of the current foreground user. Requires system permissions.
3979 * @hide
3980 */
3981 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06003982 @RequiresPermission(anyOf = {
3983 "android.permission.INTERACT_ACROSS_USERS",
3984 "android.permission.INTERACT_ACROSS_USERS_FULL"
3985 })
Dianne Hackborn41203752012-08-31 14:05:51 -07003986 public static int getCurrentUser() {
3987 UserInfo ui;
3988 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003989 ui = getService().getCurrentUser();
Dianne Hackborn41203752012-08-31 14:05:51 -07003990 return ui != null ? ui.id : 0;
3991 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003992 throw e.rethrowFromSystemServer();
Dianne Hackborn41203752012-08-31 14:05:51 -07003993 }
3994 }
3995
Amith Yamasani4b2e9342011-03-31 12:38:53 -07003996 /**
Stefan Kuhne16045c22015-06-05 07:18:06 -07003997 * @param userid the user's id. Zero indicates the default user.
Amith Yamasani4b2e9342011-03-31 12:38:53 -07003998 * @hide
3999 */
4000 public boolean switchUser(int userid) {
4001 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004002 return getService().switchUser(userid);
Amith Yamasani4b2e9342011-03-31 12:38:53 -07004003 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004004 throw e.rethrowFromSystemServer();
Amith Yamasani4b2e9342011-03-31 12:38:53 -07004005 }
4006 }
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07004007
Fyodor Kupolovb5690bc32016-03-02 17:50:58 -08004008 /**
4009 * Logs out current current foreground user by switching to the system user and stopping the
4010 * user being switched from.
4011 * @hide
4012 */
4013 public static void logoutCurrentUser() {
4014 int currentUser = ActivityManager.getCurrentUser();
4015 if (currentUser != UserHandle.USER_SYSTEM) {
4016 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004017 getService().switchUser(UserHandle.USER_SYSTEM);
4018 getService().stopUser(currentUser, /* force= */ false, null);
Fyodor Kupolovb5690bc32016-03-02 17:50:58 -08004019 } catch (RemoteException e) {
4020 e.rethrowFromSystemServer();
4021 }
4022 }
4023 }
4024
Jeff Sharkeye17ac152015-11-06 22:40:29 -08004025 /** {@hide} */
4026 public static final int FLAG_OR_STOPPED = 1 << 0;
4027 /** {@hide} */
Jeff Sharkey8924e872015-11-30 12:52:10 -07004028 public static final int FLAG_AND_LOCKED = 1 << 1;
Jeff Sharkey0825ab22015-12-02 13:04:49 -07004029 /** {@hide} */
4030 public static final int FLAG_AND_UNLOCKED = 1 << 2;
Jeff Sharkeyce18c812016-04-27 16:00:41 -06004031 /** {@hide} */
4032 public static final int FLAG_AND_UNLOCKING_OR_UNLOCKED = 1 << 3;
Jeff Sharkeye17ac152015-11-06 22:40:29 -08004033
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07004034 /**
4035 * Return whether the given user is actively running. This means that
4036 * the user is in the "started" state, not "stopped" -- it is currently
4037 * allowed to run code through scheduled alarms, receiving broadcasts,
4038 * etc. A started user may be either the current foreground user or a
4039 * background user; the result here does not distinguish between the two.
Dianne Hackborn5614bf52016-11-07 17:26:41 -08004040 * @param userId the user's id. Zero indicates the default user.
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07004041 * @hide
4042 */
Jeff Sharkey9d8a1042015-12-03 17:56:20 -07004043 public boolean isUserRunning(int userId) {
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07004044 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004045 return getService().isUserRunning(userId, 0);
Jeff Sharkey9d8a1042015-12-03 17:56:20 -07004046 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004047 throw e.rethrowFromSystemServer();
Jeff Sharkey9d8a1042015-12-03 17:56:20 -07004048 }
4049 }
4050
4051 /** {@hide} */
Ruben Brunke24b9a62016-02-16 21:38:24 -08004052 public boolean isVrModePackageEnabled(ComponentName component) {
4053 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004054 return getService().isVrModePackageEnabled(component);
Ruben Brunke24b9a62016-02-16 21:38:24 -08004055 } catch (RemoteException e) {
4056 throw e.rethrowFromSystemServer();
4057 }
4058 }
4059
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07004060 /**
4061 * Perform a system dump of various state associated with the given application
4062 * package name. This call blocks while the dump is being performed, so should
4063 * not be done on a UI thread. The data will be written to the given file
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004064 * descriptor as text.
Dianne Hackbornebc15ef2013-10-09 17:36:57 -07004065 * @param fd The file descriptor that the dump should be written to. The file
4066 * descriptor is <em>not</em> closed by this function; the caller continues to
4067 * own it.
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07004068 * @param packageName The name of the package that is to be dumped.
4069 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004070 @RequiresPermission(Manifest.permission.DUMP)
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07004071 public void dumpPackageState(FileDescriptor fd, String packageName) {
4072 dumpPackageStateStatic(fd, packageName);
4073 }
4074
4075 /**
4076 * @hide
4077 */
4078 public static void dumpPackageStateStatic(FileDescriptor fd, String packageName) {
4079 FileOutputStream fout = new FileOutputStream(fd);
Dianne Hackborn8c841092013-06-24 13:46:13 -07004080 PrintWriter pw = new FastPrintWriter(fout);
Dianne Hackbornab4a81b2014-10-09 17:59:38 -07004081 dumpService(pw, fd, "package", new String[] { packageName });
4082 pw.println();
Dianne Hackborndaa0d5c2013-11-06 16:30:29 -08004083 dumpService(pw, fd, Context.ACTIVITY_SERVICE, new String[] {
4084 "-a", "package", packageName });
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07004085 pw.println();
Dianne Hackbornab4a81b2014-10-09 17:59:38 -07004086 dumpService(pw, fd, "meminfo", new String[] { "--local", "--package", packageName });
Dianne Hackborndaa0d5c2013-11-06 16:30:29 -08004087 pw.println();
Dianne Hackbornab4a81b2014-10-09 17:59:38 -07004088 dumpService(pw, fd, ProcessStats.SERVICE_NAME, new String[] { packageName });
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07004089 pw.println();
Dianne Hackborn904a8572013-06-28 18:12:31 -07004090 dumpService(pw, fd, "usagestats", new String[] { "--packages", packageName });
4091 pw.println();
Dianne Hackborn8c841092013-06-24 13:46:13 -07004092 dumpService(pw, fd, BatteryStats.SERVICE_NAME, new String[] { packageName });
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07004093 pw.flush();
4094 }
4095
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07004096 /**
4097 * @hide
4098 */
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004099 public static boolean isSystemReady() {
4100 if (!sSystemReady) {
4101 if (ActivityThread.isSystem()) {
4102 sSystemReady =
4103 LocalServices.getService(ActivityManagerInternal.class).isSystemReady();
4104 } else {
4105 // Since this is being called from outside system server, system should be
4106 // ready by now.
4107 sSystemReady = true;
4108 }
4109 }
4110 return sSystemReady;
4111 }
4112
4113 /**
4114 * @hide
4115 */
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07004116 public static void broadcastStickyIntent(Intent intent, int userId) {
4117 broadcastStickyIntent(intent, AppOpsManager.OP_NONE, userId);
4118 }
4119
4120 /**
4121 * Convenience for sending a sticky broadcast. For internal use only.
4122 *
4123 * @hide
4124 */
4125 public static void broadcastStickyIntent(Intent intent, int appOp, int userId) {
4126 try {
4127 getService().broadcastIntent(
4128 null, intent, null, null, Activity.RESULT_OK, null, null,
4129 null /*permission*/, appOp, null, false, true, userId);
4130 } catch (RemoteException ex) {
4131 }
4132 }
4133
4134 /**
4135 * @hide
4136 */
4137 public static void noteWakeupAlarm(PendingIntent ps, int sourceUid, String sourcePkg,
4138 String tag) {
4139 try {
4140 getService().noteWakeupAlarm((ps != null) ? ps.getTarget() : null,
4141 sourceUid, sourcePkg, tag);
4142 } catch (RemoteException ex) {
4143 }
4144 }
4145
4146 /**
4147 * @hide
4148 */
4149 public static void noteAlarmStart(PendingIntent ps, int sourceUid, String tag) {
4150 try {
4151 getService().noteAlarmStart((ps != null) ? ps.getTarget() : null, sourceUid, tag);
4152 } catch (RemoteException ex) {
4153 }
4154 }
4155
4156 /**
4157 * @hide
4158 */
4159 public static void noteAlarmFinish(PendingIntent ps, int sourceUid, String tag) {
4160 try {
4161 getService().noteAlarmFinish((ps != null) ? ps.getTarget() : null, sourceUid, tag);
4162 } catch (RemoteException ex) {
4163 }
4164 }
4165
4166 /**
4167 * @hide
4168 */
4169 public static IActivityManager getService() {
4170 return IActivityManagerSingleton.get();
4171 }
4172
4173 private static final Singleton<IActivityManager> IActivityManagerSingleton =
4174 new Singleton<IActivityManager>() {
4175 @Override
4176 protected IActivityManager create() {
4177 final IBinder b = ServiceManager.getService(Context.ACTIVITY_SERVICE);
4178 final IActivityManager am = IActivityManager.Stub.asInterface(b);
4179 return am;
4180 }
4181 };
4182
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07004183 private static void dumpService(PrintWriter pw, FileDescriptor fd, String name, String[] args) {
4184 pw.print("DUMP OF SERVICE "); pw.print(name); pw.println(":");
4185 IBinder service = ServiceManager.checkService(name);
4186 if (service == null) {
4187 pw.println(" (Service not found)");
4188 return;
4189 }
4190 TransferPipe tp = null;
4191 try {
4192 pw.flush();
4193 tp = new TransferPipe();
4194 tp.setBufferPrefix(" ");
Dianne Hackborndaa0d5c2013-11-06 16:30:29 -08004195 service.dumpAsync(tp.getWriteFd().getFileDescriptor(), args);
Dianne Hackbornab4a81b2014-10-09 17:59:38 -07004196 tp.go(fd, 10000);
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07004197 } catch (Throwable e) {
4198 if (tp != null) {
4199 tp.kill();
4200 }
4201 pw.println("Failure dumping service:");
4202 e.printStackTrace(pw);
4203 }
4204 }
Craig Mautneraea74a52014-03-08 14:23:10 -08004205
4206 /**
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004207 * Request that the system start watching for the calling process to exceed a pss
Dianne Hackborn17f69352015-07-17 18:04:14 -07004208 * size as given here. Once called, the system will look for any occasions where it
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004209 * sees the associated process with a larger pss size and, when this happens, automatically
4210 * pull a heap dump from it and allow the user to share the data. Note that this request
4211 * continues running even if the process is killed and restarted. To remove the watch,
4212 * use {@link #clearWatchHeapLimit()}.
4213 *
Dianne Hackbornece0f4f2015-06-11 13:29:01 -07004214 * <p>This API only work if the calling process has been marked as
4215 * {@link ApplicationInfo#FLAG_DEBUGGABLE} or this is running on a debuggable
4216 * (userdebug or eng) build.</p>
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004217 *
4218 * <p>Callers can optionally implement {@link #ACTION_REPORT_HEAP_LIMIT} to directly
4219 * handle heap limit reports themselves.</p>
4220 *
4221 * @param pssSize The size in bytes to set the limit at.
4222 */
4223 public void setWatchHeapLimit(long pssSize) {
4224 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004225 getService().setDumpHeapDebugLimit(null, 0, pssSize,
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004226 mContext.getPackageName());
4227 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004228 throw e.rethrowFromSystemServer();
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004229 }
4230 }
4231
4232 /**
4233 * Action an app can implement to handle reports from {@link #setWatchHeapLimit(long)}.
4234 * If your package has an activity handling this action, it will be launched with the
4235 * heap data provided to it the same way as {@link Intent#ACTION_SEND}. Note that to
4236 * match the activty must support this action and a MIME type of "*&#47;*".
4237 */
4238 public static final String ACTION_REPORT_HEAP_LIMIT = "android.app.action.REPORT_HEAP_LIMIT";
4239
4240 /**
4241 * Clear a heap watch limit previously set by {@link #setWatchHeapLimit(long)}.
4242 */
4243 public void clearWatchHeapLimit() {
4244 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004245 getService().setDumpHeapDebugLimit(null, 0, 0, null);
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004246 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004247 throw e.rethrowFromSystemServer();
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004248 }
4249 }
4250
4251 /**
Craig Mautneraea74a52014-03-08 14:23:10 -08004252 * @hide
4253 */
4254 public void startLockTaskMode(int taskId) {
4255 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004256 getService().startLockTaskModeById(taskId);
Craig Mautneraea74a52014-03-08 14:23:10 -08004257 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004258 throw e.rethrowFromSystemServer();
Craig Mautneraea74a52014-03-08 14:23:10 -08004259 }
4260 }
4261
4262 /**
4263 * @hide
4264 */
4265 public void stopLockTaskMode() {
4266 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004267 getService().stopLockTaskMode();
Craig Mautneraea74a52014-03-08 14:23:10 -08004268 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004269 throw e.rethrowFromSystemServer();
Craig Mautneraea74a52014-03-08 14:23:10 -08004270 }
4271 }
4272
4273 /**
Jason Monk386c94f2014-07-14 16:42:24 -04004274 * Return whether currently in lock task mode. When in this mode
4275 * no new tasks can be created or switched to.
4276 *
4277 * @see Activity#startLockTask()
Benjamin Franz43261142015-02-11 15:59:44 +00004278 *
4279 * @deprecated Use {@link #getLockTaskModeState} instead.
Craig Mautneraea74a52014-03-08 14:23:10 -08004280 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07004281 @Deprecated
Craig Mautneraea74a52014-03-08 14:23:10 -08004282 public boolean isInLockTaskMode() {
Benjamin Franz43261142015-02-11 15:59:44 +00004283 return getLockTaskModeState() != LOCK_TASK_MODE_NONE;
4284 }
4285
4286 /**
4287 * Return the current state of task locking. The three possible outcomes
4288 * are {@link #LOCK_TASK_MODE_NONE}, {@link #LOCK_TASK_MODE_LOCKED}
4289 * and {@link #LOCK_TASK_MODE_PINNED}.
4290 *
4291 * @see Activity#startLockTask()
4292 */
4293 public int getLockTaskModeState() {
Craig Mautneraea74a52014-03-08 14:23:10 -08004294 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004295 return getService().getLockTaskModeState();
Craig Mautneraea74a52014-03-08 14:23:10 -08004296 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004297 throw e.rethrowFromSystemServer();
Craig Mautneraea74a52014-03-08 14:23:10 -08004298 }
4299 }
Winson Chung1147c402014-05-14 11:05:00 -07004300
4301 /**
Srinath Sridharane535a582016-06-27 18:13:47 -07004302 * Enable more aggressive scheduling for latency-sensitive low-runtime VR threads. Only one
4303 * thread can be a VR thread in a process at a time, and that thread may be subject to
4304 * restrictions on the amount of time it can run.
4305 *
Craig Donnerdc4796c2017-03-08 09:51:47 -08004306 * If persistent VR mode is set, whatever thread has been granted aggressive scheduling via this
4307 * method will return to normal operation, and calling this method will do nothing while
4308 * persistent VR mode is enabled.
4309 *
Srinath Sridharane535a582016-06-27 18:13:47 -07004310 * To reset the VR thread for an application, a tid of 0 can be passed.
4311 *
4312 * @see android.os.Process#myTid()
4313 * @param tid tid of the VR thread
4314 */
4315 public static void setVrThread(int tid) {
4316 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004317 getService().setVrThread(tid);
Srinath Sridharane535a582016-06-27 18:13:47 -07004318 } catch (RemoteException e) {
4319 // pass
4320 }
4321 }
4322
4323 /**
Craig Donnerdc4796c2017-03-08 09:51:47 -08004324 * Enable more aggressive scheduling for latency-sensitive low-runtime VR threads that persist
Jeff Sharkey910e0812017-04-21 16:29:27 -06004325 * beyond a single process. Only one thread can be a
Craig Donnerdc4796c2017-03-08 09:51:47 -08004326 * persistent VR thread at a time, and that thread may be subject to restrictions on the amount
4327 * of time it can run. Calling this method will disable aggressive scheduling for non-persistent
4328 * VR threads set via {@link #setVrThread}. If persistent VR mode is disabled then the
4329 * persistent VR thread loses its new scheduling priority; this method must be called again to
4330 * set the persistent thread.
4331 *
4332 * To reset the persistent VR thread, a tid of 0 can be passed.
4333 *
4334 * @see android.os.Process#myTid()
4335 * @param tid tid of the VR thread
4336 * @hide
4337 */
4338 @RequiresPermission(Manifest.permission.RESTRICTED_VR_ACCESS)
4339 public static void setPersistentVrThread(int tid) {
4340 try {
4341 getService().setPersistentVrThread(tid);
4342 } catch (RemoteException e) {
4343 // pass
4344 }
4345 }
4346
4347 /**
Winson Chung1147c402014-05-14 11:05:00 -07004348 * The AppTask allows you to manage your own application's tasks.
4349 * See {@link android.app.ActivityManager#getAppTasks()}
4350 */
4351 public static class AppTask {
4352 private IAppTask mAppTaskImpl;
4353
4354 /** @hide */
4355 public AppTask(IAppTask task) {
4356 mAppTaskImpl = task;
4357 }
4358
4359 /**
4360 * Finishes all activities in this task and removes it from the recent tasks list.
4361 */
4362 public void finishAndRemoveTask() {
4363 try {
4364 mAppTaskImpl.finishAndRemoveTask();
4365 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004366 throw e.rethrowFromSystemServer();
Winson Chung1147c402014-05-14 11:05:00 -07004367 }
4368 }
4369
4370 /**
4371 * Get the RecentTaskInfo associated with this task.
4372 *
4373 * @return The RecentTaskInfo for this task, or null if the task no longer exists.
4374 */
4375 public RecentTaskInfo getTaskInfo() {
4376 try {
4377 return mAppTaskImpl.getTaskInfo();
4378 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004379 throw e.rethrowFromSystemServer();
Winson Chung1147c402014-05-14 11:05:00 -07004380 }
4381 }
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07004382
4383 /**
Dianne Hackborn89ad4562014-08-24 16:45:38 -07004384 * Bring this task to the foreground. If it contains activities, they will be
4385 * brought to the foreground with it and their instances re-created if needed.
4386 * If it doesn't contain activities, the root activity of the task will be
4387 * re-launched.
4388 */
4389 public void moveToFront() {
4390 try {
4391 mAppTaskImpl.moveToFront();
4392 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004393 throw e.rethrowFromSystemServer();
Dianne Hackborn89ad4562014-08-24 16:45:38 -07004394 }
4395 }
4396
4397 /**
4398 * Start an activity in this task. Brings the task to the foreground. If this task
Dianne Hackborna4e102e2014-09-04 22:52:27 -07004399 * is not currently active (that is, its id < 0), then a new activity for the given
4400 * Intent will be launched as the root of the task and the task brought to the
4401 * foreground. Otherwise, if this task is currently active and the Intent does not specify
4402 * an activity to launch in a new task, then a new activity for the given Intent will
4403 * be launched on top of the task and the task brought to the foreground. If this
4404 * task is currently active and the Intent specifies {@link Intent#FLAG_ACTIVITY_NEW_TASK}
4405 * or would otherwise be launched in to a new task, then the activity not launched but
4406 * this task be brought to the foreground and a new intent delivered to the top
4407 * activity if appropriate.
Dianne Hackborn89ad4562014-08-24 16:45:38 -07004408 *
Dianne Hackborna4e102e2014-09-04 22:52:27 -07004409 * <p>In other words, you generally want to use an Intent here that does not specify
4410 * {@link Intent#FLAG_ACTIVITY_NEW_TASK} or {@link Intent#FLAG_ACTIVITY_NEW_DOCUMENT},
4411 * and let the system do the right thing.</p>
Dianne Hackborn89ad4562014-08-24 16:45:38 -07004412 *
4413 * @param intent The Intent describing the new activity to be launched on the task.
4414 * @param options Optional launch options.
Dianne Hackborna4e102e2014-09-04 22:52:27 -07004415 *
4416 * @see Activity#startActivity(android.content.Intent, android.os.Bundle)
Dianne Hackborn89ad4562014-08-24 16:45:38 -07004417 */
4418 public void startActivity(Context context, Intent intent, Bundle options) {
4419 ActivityThread thread = ActivityThread.currentActivityThread();
4420 thread.getInstrumentation().execStartActivityFromAppTask(context,
4421 thread.getApplicationThread(), mAppTaskImpl, intent, options);
4422 }
4423
4424 /**
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07004425 * Modify the {@link Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} flag in the root
4426 * Intent of this AppTask.
4427 *
4428 * @param exclude If true, {@link Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} will
4429 * be set; otherwise, it will be cleared.
4430 */
4431 public void setExcludeFromRecents(boolean exclude) {
4432 try {
4433 mAppTaskImpl.setExcludeFromRecents(exclude);
4434 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004435 throw e.rethrowFromSystemServer();
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07004436 }
4437 }
Winson Chung1147c402014-05-14 11:05:00 -07004438 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004439}