The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.app; |
| 18 | |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 19 | import android.annotation.NonNull; |
| 20 | import android.annotation.Nullable; |
Amith Yamasani | 0e8d7d6 | 2014-09-03 13:17:28 -0700 | [diff] [blame] | 21 | import android.annotation.SystemApi; |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 22 | import android.graphics.Canvas; |
| 23 | import android.graphics.Matrix; |
| 24 | import android.graphics.Point; |
Dianne Hackborn | 91268cf | 2013-06-13 19:06:50 -0700 | [diff] [blame] | 25 | import android.os.BatteryStats; |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 26 | import android.os.IBinder; |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 27 | import android.os.ParcelFileDescriptor; |
Amith Yamasani | 0e8d7d6 | 2014-09-03 13:17:28 -0700 | [diff] [blame] | 28 | |
Dianne Hackborn | 8a0de58 | 2013-08-07 15:22:07 -0700 | [diff] [blame] | 29 | import com.android.internal.app.ProcessStats; |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 30 | import com.android.internal.os.TransferPipe; |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 31 | import com.android.internal.util.FastPrintWriter; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 32 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | import android.content.ComponentName; |
| 34 | import android.content.Context; |
| 35 | import android.content.Intent; |
Suchi Amalapurapu | f7f5dda | 2010-03-23 10:34:28 -0700 | [diff] [blame] | 36 | import android.content.pm.ApplicationInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | import android.content.pm.ConfigurationInfo; |
| 38 | import android.content.pm.IPackageDataObserver; |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 39 | import android.content.pm.PackageManager; |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 40 | import android.content.pm.UserInfo; |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 41 | import android.content.res.Resources; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | import android.graphics.Bitmap; |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 43 | import android.graphics.Color; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 44 | import android.graphics.Rect; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 45 | import android.os.Bundle; |
Dianne Hackborn | 4f21c4c | 2009-09-17 10:24:05 -0700 | [diff] [blame] | 46 | import android.os.Debug; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | import android.os.Handler; |
| 48 | import android.os.Parcel; |
| 49 | import android.os.Parcelable; |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 50 | import android.os.Process; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 51 | import android.os.RemoteException; |
Peter Visontay | 8d224ca | 2011-02-18 16:39:19 +0000 | [diff] [blame] | 52 | import android.os.ServiceManager; |
Dianne Hackborn | 2c6c5e6 | 2009-10-08 17:55:49 -0700 | [diff] [blame] | 53 | import android.os.SystemProperties; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 54 | import android.os.UserHandle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | import android.text.TextUtils; |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 56 | import android.util.DisplayMetrics; |
Winson Chung | 48a10a5 | 2014-08-27 14:36:51 -0700 | [diff] [blame] | 57 | import android.util.Size; |
Dianne Hackborn | b375632 | 2011-08-12 13:58:13 -0700 | [diff] [blame] | 58 | import android.util.Slog; |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 59 | import org.xmlpull.v1.XmlSerializer; |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 60 | |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 61 | import java.io.FileDescriptor; |
| 62 | import java.io.FileOutputStream; |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 63 | import java.io.IOException; |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 64 | import java.io.PrintWriter; |
Winson Chung | 1147c40 | 2014-05-14 11:05:00 -0700 | [diff] [blame] | 65 | import java.util.ArrayList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | import java.util.List; |
| 67 | |
| 68 | /** |
| 69 | * Interact with the overall activities running in the system. |
| 70 | */ |
| 71 | public class ActivityManager { |
| 72 | private static String TAG = "ActivityManager"; |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 73 | private static boolean localLOGV = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 75 | private static int gMaxRecentTasks = -1; |
| 76 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | private final Context mContext; |
| 78 | private final Handler mHandler; |
| 79 | |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 80 | /** |
Scott Main | cc2195b | 2013-10-16 13:57:46 -0700 | [diff] [blame] | 81 | * <a href="{@docRoot}guide/topics/manifest/meta-data-element.html">{@code |
| 82 | * <meta-data>}</a> name for a 'home' Activity that declares a package that is to be |
Christopher Tate | bd413f6 | 2013-09-18 18:31:59 -0700 | [diff] [blame] | 83 | * uninstalled in lieu of the declaring one. The package named here must be |
Scott Main | cc2195b | 2013-10-16 13:57:46 -0700 | [diff] [blame] | 84 | * signed with the same certificate as the one declaring the {@code <meta-data>}. |
Christopher Tate | bd413f6 | 2013-09-18 18:31:59 -0700 | [diff] [blame] | 85 | */ |
| 86 | public static final String META_HOME_ALTERNATE = "android.app.home.alternate"; |
| 87 | |
| 88 | /** |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 89 | * Result for IActivityManager.startActivity: trying to start a background user |
| 90 | * activity that shouldn't be displayed for all users. |
| 91 | * @hide |
| 92 | */ |
| 93 | public static final int START_NOT_CURRENT_USER_ACTIVITY = -8; |
| 94 | |
| 95 | /** |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 96 | * Result for IActivityManager.startActivity: trying to start an activity under voice |
| 97 | * control when that activity does not support the VOICE category. |
| 98 | * @hide |
| 99 | */ |
| 100 | public static final int START_NOT_VOICE_COMPATIBLE = -7; |
| 101 | |
| 102 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 103 | * Result for IActivityManager.startActivity: an error where the |
| 104 | * start had to be canceled. |
| 105 | * @hide |
| 106 | */ |
| 107 | public static final int START_CANCELED = -6; |
| 108 | |
| 109 | /** |
| 110 | * Result for IActivityManager.startActivity: an error where the |
| 111 | * thing being started is not an activity. |
| 112 | * @hide |
| 113 | */ |
| 114 | public static final int START_NOT_ACTIVITY = -5; |
| 115 | |
| 116 | /** |
| 117 | * Result for IActivityManager.startActivity: an error where the |
| 118 | * caller does not have permission to start the activity. |
| 119 | * @hide |
| 120 | */ |
| 121 | public static final int START_PERMISSION_DENIED = -4; |
| 122 | |
| 123 | /** |
| 124 | * Result for IActivityManager.startActivity: an error where the |
| 125 | * caller has requested both to forward a result and to receive |
| 126 | * a result. |
| 127 | * @hide |
| 128 | */ |
| 129 | public static final int START_FORWARD_AND_REQUEST_CONFLICT = -3; |
| 130 | |
| 131 | /** |
| 132 | * Result for IActivityManager.startActivity: an error where the |
| 133 | * requested class is not found. |
| 134 | * @hide |
| 135 | */ |
| 136 | public static final int START_CLASS_NOT_FOUND = -2; |
| 137 | |
| 138 | /** |
| 139 | * Result for IActivityManager.startActivity: an error where the |
| 140 | * given Intent could not be resolved to an activity. |
| 141 | * @hide |
| 142 | */ |
| 143 | public static final int START_INTENT_NOT_RESOLVED = -1; |
| 144 | |
| 145 | /** |
| 146 | * Result for IActivityManaqer.startActivity: the activity was started |
| 147 | * successfully as normal. |
| 148 | * @hide |
| 149 | */ |
| 150 | public static final int START_SUCCESS = 0; |
| 151 | |
| 152 | /** |
| 153 | * Result for IActivityManaqer.startActivity: the caller asked that the Intent not |
| 154 | * be executed if it is the recipient, and that is indeed the case. |
| 155 | * @hide |
| 156 | */ |
| 157 | public static final int START_RETURN_INTENT_TO_CALLER = 1; |
| 158 | |
| 159 | /** |
| 160 | * Result for IActivityManaqer.startActivity: activity wasn't really started, but |
| 161 | * a task was simply brought to the foreground. |
| 162 | * @hide |
| 163 | */ |
| 164 | public static final int START_TASK_TO_FRONT = 2; |
| 165 | |
| 166 | /** |
| 167 | * Result for IActivityManaqer.startActivity: activity wasn't really started, but |
| 168 | * the given Intent was given to the existing top activity. |
| 169 | * @hide |
| 170 | */ |
| 171 | public static final int START_DELIVERED_TO_TOP = 3; |
| 172 | |
| 173 | /** |
| 174 | * Result for IActivityManaqer.startActivity: request was canceled because |
| 175 | * app switches are temporarily canceled to ensure the user's last request |
| 176 | * (such as pressing home) is performed. |
| 177 | * @hide |
| 178 | */ |
| 179 | public static final int START_SWITCHES_CANCELED = 4; |
| 180 | |
| 181 | /** |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 182 | * Result for IActivityManaqer.startActivity: a new activity was attempted to be started |
| 183 | * while in Lock Task Mode. |
| 184 | * @hide |
| 185 | */ |
| 186 | public static final int START_RETURN_LOCK_TASK_MODE_VIOLATION = 5; |
| 187 | |
| 188 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 189 | * Flag for IActivityManaqer.startActivity: do special start mode where |
| 190 | * a new activity is launched only if it is needed. |
| 191 | * @hide |
| 192 | */ |
| 193 | public static final int START_FLAG_ONLY_IF_NEEDED = 1<<0; |
| 194 | |
| 195 | /** |
| 196 | * Flag for IActivityManaqer.startActivity: launch the app for |
| 197 | * debugging. |
| 198 | * @hide |
| 199 | */ |
| 200 | public static final int START_FLAG_DEBUG = 1<<1; |
| 201 | |
| 202 | /** |
| 203 | * Flag for IActivityManaqer.startActivity: launch the app for |
| 204 | * OpenGL tracing. |
| 205 | * @hide |
| 206 | */ |
| 207 | public static final int START_FLAG_OPENGL_TRACES = 1<<2; |
| 208 | |
| 209 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 210 | * Result for IActivityManaqer.broadcastIntent: success! |
| 211 | * @hide |
| 212 | */ |
| 213 | public static final int BROADCAST_SUCCESS = 0; |
| 214 | |
| 215 | /** |
| 216 | * Result for IActivityManaqer.broadcastIntent: attempt to broadcast |
| 217 | * a sticky intent without appropriate permission. |
| 218 | * @hide |
| 219 | */ |
| 220 | public static final int BROADCAST_STICKY_CANT_HAVE_PERMISSION = -1; |
| 221 | |
| 222 | /** |
Amith Yamasani | 83b6ef0 | 2014-11-07 15:34:04 -0800 | [diff] [blame] | 223 | * Result for IActivityManager.broadcastIntent: trying to send a broadcast |
| 224 | * to a stopped user. Fail. |
| 225 | * @hide |
| 226 | */ |
| 227 | public static final int BROADCAST_FAILED_USER_STOPPED = -2; |
| 228 | |
| 229 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 230 | * Type for IActivityManaqer.getIntentSender: this PendingIntent is |
| 231 | * for a sendBroadcast operation. |
| 232 | * @hide |
| 233 | */ |
| 234 | public static final int INTENT_SENDER_BROADCAST = 1; |
| 235 | |
| 236 | /** |
| 237 | * Type for IActivityManaqer.getIntentSender: this PendingIntent is |
| 238 | * for a startActivity operation. |
| 239 | * @hide |
| 240 | */ |
| 241 | public static final int INTENT_SENDER_ACTIVITY = 2; |
| 242 | |
| 243 | /** |
| 244 | * Type for IActivityManaqer.getIntentSender: this PendingIntent is |
| 245 | * for an activity result operation. |
| 246 | * @hide |
| 247 | */ |
| 248 | public static final int INTENT_SENDER_ACTIVITY_RESULT = 3; |
| 249 | |
| 250 | /** |
| 251 | * Type for IActivityManaqer.getIntentSender: this PendingIntent is |
| 252 | * for a startService operation. |
| 253 | * @hide |
| 254 | */ |
| 255 | public static final int INTENT_SENDER_SERVICE = 4; |
| 256 | |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 257 | /** @hide User operation call: success! */ |
| 258 | public static final int USER_OP_SUCCESS = 0; |
| 259 | |
| 260 | /** @hide User operation call: given user id is not known. */ |
| 261 | public static final int USER_OP_UNKNOWN_USER = -1; |
| 262 | |
| 263 | /** @hide User operation call: given user id is the current user, can't be stopped. */ |
| 264 | public static final int USER_OP_IS_CURRENT = -2; |
| 265 | |
Ruben Brunk | a27eef4 | 2015-01-28 15:04:16 -0800 | [diff] [blame] | 266 | /** @hide Process does not exist. */ |
| 267 | public static final int PROCESS_STATE_NONEXISTENT = -1; |
| 268 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 269 | /** @hide Process is a persistent system process. */ |
| 270 | public static final int PROCESS_STATE_PERSISTENT = 0; |
| 271 | |
| 272 | /** @hide Process is a persistent system process and is doing UI. */ |
| 273 | public static final int PROCESS_STATE_PERSISTENT_UI = 1; |
| 274 | |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 275 | /** @hide Process is hosting the current top activities. Note that this covers |
| 276 | * all activities that are visible to the user. */ |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 277 | public static final int PROCESS_STATE_TOP = 2; |
| 278 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 279 | /** @hide Process is hosting a foreground service. */ |
| 280 | public static final int PROCESS_STATE_FOREGROUND_SERVICE = 3; |
| 281 | |
| 282 | /** @hide Same as {@link #PROCESS_STATE_TOP} but while device is sleeping. */ |
| 283 | public static final int PROCESS_STATE_TOP_SLEEPING = 4; |
| 284 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 285 | /** @hide Process is important to the user, and something they are aware of. */ |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 286 | public static final int PROCESS_STATE_IMPORTANT_FOREGROUND = 5; |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 287 | |
| 288 | /** @hide Process is important to the user, but not something they are aware of. */ |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 289 | public static final int PROCESS_STATE_IMPORTANT_BACKGROUND = 6; |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 290 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 291 | /** @hide Process is in the background running a backup/restore operation. */ |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 292 | public static final int PROCESS_STATE_BACKUP = 7; |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 293 | |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 294 | /** @hide Process is in the background, but it can't restore its state so we want |
| 295 | * to try to avoid killing it. */ |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 296 | public static final int PROCESS_STATE_HEAVY_WEIGHT = 8; |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 297 | |
| 298 | /** @hide Process is in the background running a service. Unlike oom_adj, this level |
| 299 | * is used for both the normal running in background state and the executing |
| 300 | * operations state. */ |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 301 | public static final int PROCESS_STATE_SERVICE = 9; |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 302 | |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 303 | /** @hide Process is in the background running a receiver. Note that from the |
| 304 | * perspective of oom_adj receivers run at a higher foreground level, but for our |
| 305 | * prioritization here that is not necessary and putting them below services means |
| 306 | * many fewer changes in some process states as they receive broadcasts. */ |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 307 | public static final int PROCESS_STATE_RECEIVER = 10; |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 308 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 309 | /** @hide Process is in the background but hosts the home activity. */ |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 310 | public static final int PROCESS_STATE_HOME = 11; |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 311 | |
| 312 | /** @hide Process is in the background but hosts the last shown activity. */ |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 313 | public static final int PROCESS_STATE_LAST_ACTIVITY = 12; |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 314 | |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 315 | /** @hide Process is being cached for later use and contains activities. */ |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 316 | public static final int PROCESS_STATE_CACHED_ACTIVITY = 13; |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 317 | |
| 318 | /** @hide Process is being cached for later use and is a client of another cached |
| 319 | * process that contains activities. */ |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 320 | public static final int PROCESS_STATE_CACHED_ACTIVITY_CLIENT = 14; |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 321 | |
| 322 | /** @hide Process is being cached for later use and is empty. */ |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 323 | public static final int PROCESS_STATE_CACHED_EMPTY = 15; |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 324 | |
Dianne Hackborn | a83ce1d | 2015-03-11 15:16:13 -0700 | [diff] [blame] | 325 | /** @hide requestType for assist context: only basic information. */ |
| 326 | public static final int ASSIST_CONTEXT_BASIC = 0; |
| 327 | |
| 328 | /** @hide requestType for assist context: generate full AssistStructure. */ |
| 329 | public static final int ASSIST_CONTEXT_FULL = 1; |
| 330 | |
Benjamin Franz | 4326114 | 2015-02-11 15:59:44 +0000 | [diff] [blame] | 331 | /** |
| 332 | * Lock task mode is not active. |
| 333 | */ |
| 334 | public static final int LOCK_TASK_MODE_NONE = 0; |
| 335 | |
| 336 | /** |
| 337 | * Full lock task mode is active. |
| 338 | */ |
| 339 | public static final int LOCK_TASK_MODE_LOCKED = 1; |
| 340 | |
| 341 | /** |
| 342 | * App pinning mode is active. |
| 343 | */ |
| 344 | public static final int LOCK_TASK_MODE_PINNED = 2; |
| 345 | |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 346 | Point mAppTaskThumbnailSize; |
| 347 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 348 | /*package*/ ActivityManager(Context context, Handler handler) { |
| 349 | mContext = context; |
| 350 | mHandler = handler; |
| 351 | } |
| 352 | |
| 353 | /** |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 354 | * Screen compatibility mode: the application most always run in |
| 355 | * compatibility mode. |
| 356 | * @hide |
| 357 | */ |
| 358 | public static final int COMPAT_MODE_ALWAYS = -1; |
| 359 | |
| 360 | /** |
| 361 | * Screen compatibility mode: the application can never run in |
| 362 | * compatibility mode. |
| 363 | * @hide |
| 364 | */ |
| 365 | public static final int COMPAT_MODE_NEVER = -2; |
| 366 | |
| 367 | /** |
| 368 | * Screen compatibility mode: unknown. |
| 369 | * @hide |
| 370 | */ |
| 371 | public static final int COMPAT_MODE_UNKNOWN = -3; |
| 372 | |
| 373 | /** |
| 374 | * Screen compatibility mode: the application currently has compatibility |
| 375 | * mode disabled. |
| 376 | * @hide |
| 377 | */ |
| 378 | public static final int COMPAT_MODE_DISABLED = 0; |
| 379 | |
| 380 | /** |
| 381 | * Screen compatibility mode: the application currently has compatibility |
| 382 | * mode enabled. |
| 383 | * @hide |
| 384 | */ |
| 385 | public static final int COMPAT_MODE_ENABLED = 1; |
| 386 | |
| 387 | /** |
| 388 | * Screen compatibility mode: request to toggle the application's |
| 389 | * compatibility mode. |
| 390 | * @hide |
| 391 | */ |
| 392 | public static final int COMPAT_MODE_TOGGLE = 2; |
| 393 | |
| 394 | /** @hide */ |
| 395 | public int getFrontActivityScreenCompatMode() { |
| 396 | try { |
| 397 | return ActivityManagerNative.getDefault().getFrontActivityScreenCompatMode(); |
| 398 | } catch (RemoteException e) { |
| 399 | // System dead, we will be dead too soon! |
| 400 | return 0; |
| 401 | } |
| 402 | } |
| 403 | |
Dianne Hackborn | df9799f | 2011-05-12 15:16:33 -0700 | [diff] [blame] | 404 | /** @hide */ |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 405 | public void setFrontActivityScreenCompatMode(int mode) { |
| 406 | try { |
| 407 | ActivityManagerNative.getDefault().setFrontActivityScreenCompatMode(mode); |
| 408 | } catch (RemoteException e) { |
| 409 | // System dead, we will be dead too soon! |
| 410 | } |
| 411 | } |
| 412 | |
Dianne Hackborn | df9799f | 2011-05-12 15:16:33 -0700 | [diff] [blame] | 413 | /** @hide */ |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 414 | public int getPackageScreenCompatMode(String packageName) { |
| 415 | try { |
| 416 | return ActivityManagerNative.getDefault().getPackageScreenCompatMode(packageName); |
| 417 | } catch (RemoteException e) { |
| 418 | // System dead, we will be dead too soon! |
| 419 | return 0; |
| 420 | } |
| 421 | } |
| 422 | |
Dianne Hackborn | df9799f | 2011-05-12 15:16:33 -0700 | [diff] [blame] | 423 | /** @hide */ |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 424 | public void setPackageScreenCompatMode(String packageName, int mode) { |
| 425 | try { |
| 426 | ActivityManagerNative.getDefault().setPackageScreenCompatMode(packageName, mode); |
| 427 | } catch (RemoteException e) { |
| 428 | // System dead, we will be dead too soon! |
| 429 | } |
| 430 | } |
| 431 | |
Dianne Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 432 | /** @hide */ |
| 433 | public boolean getPackageAskScreenCompat(String packageName) { |
| 434 | try { |
| 435 | return ActivityManagerNative.getDefault().getPackageAskScreenCompat(packageName); |
| 436 | } catch (RemoteException e) { |
| 437 | // System dead, we will be dead too soon! |
| 438 | return false; |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | /** @hide */ |
| 443 | public void setPackageAskScreenCompat(String packageName, boolean ask) { |
| 444 | try { |
| 445 | ActivityManagerNative.getDefault().setPackageAskScreenCompat(packageName, ask); |
| 446 | } catch (RemoteException e) { |
| 447 | // System dead, we will be dead too soon! |
| 448 | } |
| 449 | } |
| 450 | |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 451 | /** |
Dianne Hackborn | 2c6c5e6 | 2009-10-08 17:55:49 -0700 | [diff] [blame] | 452 | * Return the approximate per-application memory class of the current |
| 453 | * device. This gives you an idea of how hard a memory limit you should |
| 454 | * impose on your application to let the overall system work best. The |
| 455 | * returned value is in megabytes; the baseline Android memory class is |
| 456 | * 16 (which happens to be the Java heap limit of those devices); some |
| 457 | * device with more memory may return 24 or even higher numbers. |
| 458 | */ |
| 459 | public int getMemoryClass() { |
| 460 | return staticGetMemoryClass(); |
| 461 | } |
| 462 | |
| 463 | /** @hide */ |
| 464 | static public int staticGetMemoryClass() { |
| 465 | // Really brain dead right now -- just take this from the configured |
| 466 | // vm heap size, and assume it is in megabytes and thus ends with "m". |
Dianne Hackborn | 7ad33c8 | 2011-03-08 15:53:25 -0800 | [diff] [blame] | 467 | String vmHeapSize = SystemProperties.get("dalvik.vm.heapgrowthlimit", ""); |
Dianne Hackborn | de39851 | 2011-01-18 18:45:21 -0800 | [diff] [blame] | 468 | if (vmHeapSize != null && !"".equals(vmHeapSize)) { |
| 469 | return Integer.parseInt(vmHeapSize.substring(0, vmHeapSize.length()-1)); |
| 470 | } |
| 471 | return staticGetLargeMemoryClass(); |
Dianne Hackborn | 4e24aac | 2010-12-23 11:43:46 -0800 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | /** |
| 475 | * Return the approximate per-application memory class of the current |
| 476 | * device when an application is running with a large heap. This is the |
| 477 | * space available for memory-intensive applications; most applications |
| 478 | * should not need this amount of memory, and should instead stay with the |
| 479 | * {@link #getMemoryClass()} limit. The returned value is in megabytes. |
| 480 | * This may be the same size as {@link #getMemoryClass()} on memory |
| 481 | * constrained devices, or it may be significantly larger on devices with |
| 482 | * a large amount of available RAM. |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 483 | * |
| 484 | * <p>The is the size of the application's Dalvik heap if it has |
| 485 | * specified <code>android:largeHeap="true"</code> in its manifest. |
Dianne Hackborn | 4e24aac | 2010-12-23 11:43:46 -0800 | [diff] [blame] | 486 | */ |
| 487 | public int getLargeMemoryClass() { |
| 488 | return staticGetLargeMemoryClass(); |
| 489 | } |
| 490 | |
| 491 | /** @hide */ |
| 492 | static public int staticGetLargeMemoryClass() { |
| 493 | // Really brain dead right now -- just take this from the configured |
| 494 | // vm heap size, and assume it is in megabytes and thus ends with "m". |
Dianne Hackborn | 2c6c5e6 | 2009-10-08 17:55:49 -0700 | [diff] [blame] | 495 | String vmHeapSize = SystemProperties.get("dalvik.vm.heapsize", "16m"); |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 496 | return Integer.parseInt(vmHeapSize.substring(0, vmHeapSize.length() - 1)); |
Dianne Hackborn | 2c6c5e6 | 2009-10-08 17:55:49 -0700 | [diff] [blame] | 497 | } |
Dianne Hackborn | b4e1249 | 2013-06-26 15:08:19 -0700 | [diff] [blame] | 498 | |
| 499 | /** |
| 500 | * Returns true if this is a low-RAM device. Exactly whether a device is low-RAM |
| 501 | * is ultimately up to the device configuration, but currently it generally means |
| 502 | * something in the class of a 512MB device with about a 800x480 or less screen. |
| 503 | * This is mostly intended to be used by apps to determine whether they should turn |
| 504 | * off certain features that require more RAM. |
| 505 | */ |
| 506 | public boolean isLowRamDevice() { |
| 507 | return isLowRamDeviceStatic(); |
| 508 | } |
| 509 | |
| 510 | /** @hide */ |
| 511 | public static boolean isLowRamDeviceStatic() { |
Christopher Tate | 2f61f91 | 2013-08-20 13:55:50 -0700 | [diff] [blame] | 512 | return "true".equals(SystemProperties.get("ro.config.low_ram", "false")); |
Dianne Hackborn | b4e1249 | 2013-06-26 15:08:19 -0700 | [diff] [blame] | 513 | } |
| 514 | |
Dianne Hackborn | 2c6c5e6 | 2009-10-08 17:55:49 -0700 | [diff] [blame] | 515 | /** |
Dianne Hackborn | b375632 | 2011-08-12 13:58:13 -0700 | [diff] [blame] | 516 | * Used by persistent processes to determine if they are running on a |
| 517 | * higher-end device so should be okay using hardware drawing acceleration |
| 518 | * (which tends to consume a lot more RAM). |
| 519 | * @hide |
| 520 | */ |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 521 | static public boolean isHighEndGfx() { |
Dianne Hackborn | b4e1249 | 2013-06-26 15:08:19 -0700 | [diff] [blame] | 522 | return !isLowRamDeviceStatic() && |
| 523 | !Resources.getSystem().getBoolean(com.android.internal.R.bool.config_avoidGfxAccel); |
Dianne Hackborn | 49d228b3 | 2011-08-24 17:37:31 -0700 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | /** |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 527 | * Return the maximum number of recents entries that we will maintain and show. |
| 528 | * @hide |
| 529 | */ |
| 530 | static public int getMaxRecentTasksStatic() { |
| 531 | if (gMaxRecentTasks < 0) { |
| 532 | return gMaxRecentTasks = isLowRamDeviceStatic() ? 50 : 100; |
| 533 | } |
| 534 | return gMaxRecentTasks; |
| 535 | } |
| 536 | |
| 537 | /** |
| 538 | * Return the default limit on the number of recents that an app can make. |
| 539 | * @hide |
| 540 | */ |
| 541 | static public int getDefaultAppRecentsLimitStatic() { |
| 542 | return getMaxRecentTasksStatic() / 6; |
| 543 | } |
| 544 | |
| 545 | /** |
| 546 | * Return the maximum limit on the number of recents that an app can make. |
| 547 | * @hide |
| 548 | */ |
| 549 | static public int getMaxAppRecentsLimitStatic() { |
| 550 | return getMaxRecentTasksStatic() / 2; |
| 551 | } |
| 552 | |
| 553 | /** |
Winson Chung | 1147c40 | 2014-05-14 11:05:00 -0700 | [diff] [blame] | 554 | * Information you can set and retrieve about the current activity within the recent task list. |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 555 | */ |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 556 | public static class TaskDescription implements Parcelable { |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 557 | /** @hide */ |
| 558 | public static final String ATTR_TASKDESCRIPTION_PREFIX = "task_description_"; |
| 559 | private static final String ATTR_TASKDESCRIPTIONLABEL = |
| 560 | ATTR_TASKDESCRIPTION_PREFIX + "label"; |
| 561 | private static final String ATTR_TASKDESCRIPTIONCOLOR = |
| 562 | ATTR_TASKDESCRIPTION_PREFIX + "color"; |
| 563 | private static final String ATTR_TASKDESCRIPTIONICONFILENAME = |
| 564 | ATTR_TASKDESCRIPTION_PREFIX + "icon_filename"; |
| 565 | |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 566 | private String mLabel; |
| 567 | private Bitmap mIcon; |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 568 | private String mIconFilename; |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 569 | private int mColorPrimary; |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 570 | |
| 571 | /** |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 572 | * Creates the TaskDescription to the specified values. |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 573 | * |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 574 | * @param label A label and description of the current state of this task. |
| 575 | * @param icon An icon that represents the current state of this task. |
| 576 | * @param colorPrimary A color to override the theme's primary color. This color must be opaque. |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 577 | */ |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 578 | public TaskDescription(String label, Bitmap icon, int colorPrimary) { |
| 579 | if ((colorPrimary != 0) && (Color.alpha(colorPrimary) != 255)) { |
| 580 | throw new RuntimeException("A TaskDescription's primary color should be opaque"); |
| 581 | } |
| 582 | |
| 583 | mLabel = label; |
| 584 | mIcon = icon; |
| 585 | mColorPrimary = colorPrimary; |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 586 | } |
| 587 | |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 588 | /** @hide */ |
| 589 | public TaskDescription(String label, int colorPrimary, String iconFilename) { |
| 590 | this(label, null, colorPrimary); |
| 591 | mIconFilename = iconFilename; |
| 592 | } |
| 593 | |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 594 | /** |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 595 | * Creates the TaskDescription to the specified values. |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 596 | * |
| 597 | * @param label A label and description of the current state of this activity. |
| 598 | * @param icon An icon that represents the current state of this activity. |
| 599 | */ |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 600 | public TaskDescription(String label, Bitmap icon) { |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 601 | this(label, icon, 0); |
| 602 | } |
| 603 | |
| 604 | /** |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 605 | * Creates the TaskDescription to the specified values. |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 606 | * |
| 607 | * @param label A label and description of the current state of this activity. |
| 608 | */ |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 609 | public TaskDescription(String label) { |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 610 | this(label, null, 0); |
| 611 | } |
| 612 | |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 613 | /** |
| 614 | * Creates an empty TaskDescription. |
| 615 | */ |
| 616 | public TaskDescription() { |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 617 | this(null, null, 0); |
| 618 | } |
| 619 | |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 620 | /** |
| 621 | * Creates a copy of another TaskDescription. |
| 622 | */ |
| 623 | public TaskDescription(TaskDescription td) { |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 624 | mLabel = td.mLabel; |
| 625 | mIcon = td.mIcon; |
Winson Chung | ae12dae | 2014-09-29 14:21:26 -0700 | [diff] [blame] | 626 | mColorPrimary = td.mColorPrimary; |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 627 | mIconFilename = td.mIconFilename; |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | private TaskDescription(Parcel source) { |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 631 | readFromParcel(source); |
| 632 | } |
| 633 | |
| 634 | /** |
Winson Chung | 2cb86c7 | 2014-06-25 12:03:30 -0700 | [diff] [blame] | 635 | * Sets the label for this task description. |
| 636 | * @hide |
| 637 | */ |
| 638 | public void setLabel(String label) { |
| 639 | mLabel = label; |
| 640 | } |
| 641 | |
| 642 | /** |
| 643 | * Sets the primary color for this task description. |
| 644 | * @hide |
| 645 | */ |
| 646 | public void setPrimaryColor(int primaryColor) { |
Winson Chung | ae12dae | 2014-09-29 14:21:26 -0700 | [diff] [blame] | 647 | // Ensure that the given color is valid |
| 648 | if ((primaryColor != 0) && (Color.alpha(primaryColor) != 255)) { |
| 649 | throw new RuntimeException("A TaskDescription's primary color should be opaque"); |
| 650 | } |
| 651 | mColorPrimary = primaryColor; |
Winson Chung | 2cb86c7 | 2014-06-25 12:03:30 -0700 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | /** |
| 655 | * Sets the icon for this task description. |
| 656 | * @hide |
| 657 | */ |
| 658 | public void setIcon(Bitmap icon) { |
| 659 | mIcon = icon; |
| 660 | } |
| 661 | |
| 662 | /** |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 663 | * Moves the icon bitmap reference from an actual Bitmap to a file containing the |
| 664 | * bitmap. |
| 665 | * @hide |
| 666 | */ |
| 667 | public void setIconFilename(String iconFilename) { |
| 668 | mIconFilename = iconFilename; |
| 669 | mIcon = null; |
| 670 | } |
| 671 | |
| 672 | /** |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 673 | * @return The label and description of the current state of this task. |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 674 | */ |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 675 | public String getLabel() { |
| 676 | return mLabel; |
| 677 | } |
| 678 | |
| 679 | /** |
| 680 | * @return The icon that represents the current state of this task. |
| 681 | */ |
| 682 | public Bitmap getIcon() { |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 683 | if (mIcon != null) { |
| 684 | return mIcon; |
| 685 | } |
Jorim Jaggi | bdd4b20 | 2014-09-26 18:29:07 +0200 | [diff] [blame] | 686 | return loadTaskDescriptionIcon(mIconFilename); |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | /** @hide */ |
| 690 | public String getIconFilename() { |
| 691 | return mIconFilename; |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 692 | } |
| 693 | |
Jorim Jaggi | bdd4b20 | 2014-09-26 18:29:07 +0200 | [diff] [blame] | 694 | /** @hide */ |
| 695 | public Bitmap getInMemoryIcon() { |
| 696 | return mIcon; |
| 697 | } |
| 698 | |
| 699 | /** @hide */ |
| 700 | public static Bitmap loadTaskDescriptionIcon(String iconFilename) { |
| 701 | if (iconFilename != null) { |
| 702 | try { |
| 703 | return ActivityManagerNative.getDefault(). |
| 704 | getTaskDescriptionIcon(iconFilename); |
| 705 | } catch (RemoteException e) { |
| 706 | } |
| 707 | } |
| 708 | return null; |
| 709 | } |
| 710 | |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 711 | /** |
| 712 | * @return The color override on the theme's primary color. |
| 713 | */ |
| 714 | public int getPrimaryColor() { |
| 715 | return mColorPrimary; |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 716 | } |
| 717 | |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 718 | /** @hide */ |
| 719 | public void saveToXml(XmlSerializer out) throws IOException { |
| 720 | if (mLabel != null) { |
| 721 | out.attribute(null, ATTR_TASKDESCRIPTIONLABEL, mLabel); |
| 722 | } |
| 723 | if (mColorPrimary != 0) { |
| 724 | out.attribute(null, ATTR_TASKDESCRIPTIONCOLOR, Integer.toHexString(mColorPrimary)); |
| 725 | } |
| 726 | if (mIconFilename != null) { |
| 727 | out.attribute(null, ATTR_TASKDESCRIPTIONICONFILENAME, mIconFilename); |
| 728 | } |
| 729 | } |
| 730 | |
| 731 | /** @hide */ |
| 732 | public void restoreFromXml(String attrName, String attrValue) { |
| 733 | if (ATTR_TASKDESCRIPTIONLABEL.equals(attrName)) { |
| 734 | setLabel(attrValue); |
| 735 | } else if (ATTR_TASKDESCRIPTIONCOLOR.equals(attrName)) { |
| 736 | setPrimaryColor((int) Long.parseLong(attrValue, 16)); |
| 737 | } else if (ATTR_TASKDESCRIPTIONICONFILENAME.equals(attrName)) { |
| 738 | setIconFilename(attrValue); |
| 739 | } |
| 740 | } |
| 741 | |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 742 | @Override |
| 743 | public int describeContents() { |
| 744 | return 0; |
| 745 | } |
| 746 | |
| 747 | @Override |
| 748 | public void writeToParcel(Parcel dest, int flags) { |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 749 | if (mLabel == null) { |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 750 | dest.writeInt(0); |
| 751 | } else { |
| 752 | dest.writeInt(1); |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 753 | dest.writeString(mLabel); |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 754 | } |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 755 | if (mIcon == null) { |
| 756 | dest.writeInt(0); |
| 757 | } else { |
| 758 | dest.writeInt(1); |
| 759 | mIcon.writeToParcel(dest, 0); |
| 760 | } |
| 761 | dest.writeInt(mColorPrimary); |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 762 | if (mIconFilename == null) { |
| 763 | dest.writeInt(0); |
| 764 | } else { |
| 765 | dest.writeInt(1); |
| 766 | dest.writeString(mIconFilename); |
| 767 | } |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | public void readFromParcel(Parcel source) { |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 771 | mLabel = source.readInt() > 0 ? source.readString() : null; |
| 772 | mIcon = source.readInt() > 0 ? Bitmap.CREATOR.createFromParcel(source) : null; |
| 773 | mColorPrimary = source.readInt(); |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 774 | mIconFilename = source.readInt() > 0 ? source.readString() : null; |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 775 | } |
| 776 | |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 777 | public static final Creator<TaskDescription> CREATOR |
| 778 | = new Creator<TaskDescription>() { |
| 779 | public TaskDescription createFromParcel(Parcel source) { |
| 780 | return new TaskDescription(source); |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 781 | } |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 782 | public TaskDescription[] newArray(int size) { |
| 783 | return new TaskDescription[size]; |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 784 | } |
| 785 | }; |
| 786 | |
| 787 | @Override |
| 788 | public String toString() { |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 789 | return "TaskDescription Label: " + mLabel + " Icon: " + mIcon + |
| 790 | " colorPrimary: " + mColorPrimary; |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 791 | } |
| 792 | } |
| 793 | |
| 794 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 795 | * Information you can retrieve about tasks that the user has most recently |
| 796 | * started or visited. |
| 797 | */ |
| 798 | public static class RecentTaskInfo implements Parcelable { |
| 799 | /** |
| 800 | * If this task is currently running, this is the identifier for it. |
| 801 | * If it is not running, this will be -1. |
| 802 | */ |
| 803 | public int id; |
| 804 | |
| 805 | /** |
Dianne Hackborn | d94df45 | 2011-02-16 18:53:31 -0800 | [diff] [blame] | 806 | * The true identifier of this task, valid even if it is not running. |
| 807 | */ |
| 808 | public int persistentId; |
| 809 | |
| 810 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 811 | * The original Intent used to launch the task. You can use this |
| 812 | * Intent to re-launch the task (if it is no longer running) or bring |
| 813 | * the current task to the front. |
| 814 | */ |
| 815 | public Intent baseIntent; |
| 816 | |
| 817 | /** |
| 818 | * If this task was started from an alias, this is the actual |
| 819 | * activity component that was initially started; the component of |
| 820 | * the baseIntent in this case is the name of the actual activity |
| 821 | * implementation that the alias referred to. Otherwise, this is null. |
| 822 | */ |
| 823 | public ComponentName origActivity; |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 824 | |
| 825 | /** |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 826 | * Description of the task's last state. |
| 827 | */ |
| 828 | public CharSequence description; |
Craig Mautner | 6d90fed | 2013-05-22 15:03:10 -0700 | [diff] [blame] | 829 | |
| 830 | /** |
| 831 | * The id of the ActivityStack this Task was on most recently. |
Craig Mautner | 2703052 | 2013-08-26 12:25:36 -0700 | [diff] [blame] | 832 | * @hide |
Craig Mautner | 6d90fed | 2013-05-22 15:03:10 -0700 | [diff] [blame] | 833 | */ |
| 834 | public int stackId; |
| 835 | |
Kenny Guy | 82326a9 | 2014-03-17 17:16:06 +0000 | [diff] [blame] | 836 | /** |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 837 | * The id of the user the task was running as. |
Kenny Guy | 82326a9 | 2014-03-17 17:16:06 +0000 | [diff] [blame] | 838 | * @hide |
| 839 | */ |
| 840 | public int userId; |
| 841 | |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 842 | /** |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 843 | * The first time this task was active. |
| 844 | * @hide |
| 845 | */ |
| 846 | public long firstActiveTime; |
| 847 | |
| 848 | /** |
Winson Chung | f1fbd77 | 2014-06-24 18:06:58 -0700 | [diff] [blame] | 849 | * The last time this task was active. |
| 850 | * @hide |
| 851 | */ |
| 852 | public long lastActiveTime; |
| 853 | |
| 854 | /** |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 855 | * The recent activity values for the highest activity in the stack to have set the values. |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 856 | * {@link Activity#setTaskDescription(android.app.ActivityManager.TaskDescription)}. |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 857 | */ |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 858 | public TaskDescription taskDescription; |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 859 | |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 860 | /** |
| 861 | * Task affiliation for grouping with other tasks. |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 862 | */ |
| 863 | public int affiliatedTaskId; |
| 864 | |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame] | 865 | /** |
| 866 | * Task affiliation color of the source task with the affiliated task id. |
| 867 | * |
| 868 | * @hide |
| 869 | */ |
| 870 | public int affiliatedTaskColor; |
| 871 | |
Wale Ogunwale | 6035e01 | 2015-04-14 15:54:10 -0700 | [diff] [blame] | 872 | /** |
| 873 | * The component launched as the first activity in the task. |
| 874 | * This can be considered the "application" of this task. |
| 875 | */ |
| 876 | public ComponentName baseActivity; |
| 877 | |
| 878 | /** |
| 879 | * The activity component at the top of the history stack of the task. |
| 880 | * This is what the user is currently doing. |
| 881 | */ |
| 882 | public ComponentName topActivity; |
| 883 | |
| 884 | /** |
| 885 | * Number of activities in this task. |
| 886 | */ |
| 887 | public int numActivities; |
| 888 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 889 | public RecentTaskInfo() { |
| 890 | } |
| 891 | |
Craig Mautner | 6d90fed | 2013-05-22 15:03:10 -0700 | [diff] [blame] | 892 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 893 | public int describeContents() { |
| 894 | return 0; |
| 895 | } |
| 896 | |
Craig Mautner | 6d90fed | 2013-05-22 15:03:10 -0700 | [diff] [blame] | 897 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 898 | public void writeToParcel(Parcel dest, int flags) { |
| 899 | dest.writeInt(id); |
Dianne Hackborn | d94df45 | 2011-02-16 18:53:31 -0800 | [diff] [blame] | 900 | dest.writeInt(persistentId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 901 | if (baseIntent != null) { |
| 902 | dest.writeInt(1); |
| 903 | baseIntent.writeToParcel(dest, 0); |
| 904 | } else { |
| 905 | dest.writeInt(0); |
| 906 | } |
| 907 | ComponentName.writeToParcel(origActivity, dest); |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 908 | TextUtils.writeToParcel(description, dest, |
| 909 | Parcelable.PARCELABLE_WRITE_RETURN_VALUE); |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 910 | if (taskDescription != null) { |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 911 | dest.writeInt(1); |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 912 | taskDescription.writeToParcel(dest, 0); |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 913 | } else { |
| 914 | dest.writeInt(0); |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 915 | } |
Craig Mautner | 6d90fed | 2013-05-22 15:03:10 -0700 | [diff] [blame] | 916 | dest.writeInt(stackId); |
Kenny Guy | 82326a9 | 2014-03-17 17:16:06 +0000 | [diff] [blame] | 917 | dest.writeInt(userId); |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 918 | dest.writeLong(firstActiveTime); |
Winson Chung | f1fbd77 | 2014-06-24 18:06:58 -0700 | [diff] [blame] | 919 | dest.writeLong(lastActiveTime); |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 920 | dest.writeInt(affiliatedTaskId); |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame] | 921 | dest.writeInt(affiliatedTaskColor); |
Wale Ogunwale | 6035e01 | 2015-04-14 15:54:10 -0700 | [diff] [blame] | 922 | ComponentName.writeToParcel(baseActivity, dest); |
| 923 | ComponentName.writeToParcel(topActivity, dest); |
| 924 | dest.writeInt(numActivities); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | public void readFromParcel(Parcel source) { |
| 928 | id = source.readInt(); |
Dianne Hackborn | d94df45 | 2011-02-16 18:53:31 -0800 | [diff] [blame] | 929 | persistentId = source.readInt(); |
Craig Mautner | 688b510 | 2014-03-27 16:55:03 -0700 | [diff] [blame] | 930 | baseIntent = source.readInt() > 0 ? Intent.CREATOR.createFromParcel(source) : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 931 | origActivity = ComponentName.readFromParcel(source); |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 932 | description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 933 | taskDescription = source.readInt() > 0 ? |
| 934 | TaskDescription.CREATOR.createFromParcel(source) : null; |
Craig Mautner | 6d90fed | 2013-05-22 15:03:10 -0700 | [diff] [blame] | 935 | stackId = source.readInt(); |
Kenny Guy | 82326a9 | 2014-03-17 17:16:06 +0000 | [diff] [blame] | 936 | userId = source.readInt(); |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 937 | firstActiveTime = source.readLong(); |
Winson Chung | f1fbd77 | 2014-06-24 18:06:58 -0700 | [diff] [blame] | 938 | lastActiveTime = source.readLong(); |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 939 | affiliatedTaskId = source.readInt(); |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame] | 940 | affiliatedTaskColor = source.readInt(); |
Wale Ogunwale | 6035e01 | 2015-04-14 15:54:10 -0700 | [diff] [blame] | 941 | baseActivity = ComponentName.readFromParcel(source); |
| 942 | topActivity = ComponentName.readFromParcel(source); |
| 943 | numActivities = source.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 944 | } |
Craig Mautner | 6d90fed | 2013-05-22 15:03:10 -0700 | [diff] [blame] | 945 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 946 | public static final Creator<RecentTaskInfo> CREATOR |
| 947 | = new Creator<RecentTaskInfo>() { |
| 948 | public RecentTaskInfo createFromParcel(Parcel source) { |
| 949 | return new RecentTaskInfo(source); |
| 950 | } |
| 951 | public RecentTaskInfo[] newArray(int size) { |
| 952 | return new RecentTaskInfo[size]; |
| 953 | } |
| 954 | }; |
| 955 | |
| 956 | private RecentTaskInfo(Parcel source) { |
| 957 | readFromParcel(source); |
| 958 | } |
| 959 | } |
| 960 | |
| 961 | /** |
| 962 | * Flag for use with {@link #getRecentTasks}: return all tasks, even those |
| 963 | * that have set their |
| 964 | * {@link android.content.Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} flag. |
| 965 | */ |
| 966 | public static final int RECENT_WITH_EXCLUDED = 0x0001; |
Kenny Guy | 82326a9 | 2014-03-17 17:16:06 +0000 | [diff] [blame] | 967 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 968 | /** |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 969 | * Provides a list that does not contain any |
Dianne Hackborn | 53d9264d | 2010-04-13 12:49:14 -0700 | [diff] [blame] | 970 | * recent tasks that currently are not available to the user. |
| 971 | */ |
| 972 | public static final int RECENT_IGNORE_UNAVAILABLE = 0x0002; |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 973 | |
| 974 | /** |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 975 | * Provides a list that contains recent tasks for all |
| 976 | * profiles of a user. |
Kenny Guy | 82326a9 | 2014-03-17 17:16:06 +0000 | [diff] [blame] | 977 | * @hide |
| 978 | */ |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 979 | public static final int RECENT_INCLUDE_PROFILES = 0x0004; |
Kenny Guy | 82326a9 | 2014-03-17 17:16:06 +0000 | [diff] [blame] | 980 | |
| 981 | /** |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 982 | * Ignores all tasks that are on the home stack. |
| 983 | * @hide |
| 984 | */ |
| 985 | public static final int RECENT_IGNORE_HOME_STACK_TASKS = 0x0008; |
| 986 | |
| 987 | /** |
Dianne Hackborn | a25a8b2 | 2014-05-30 12:30:35 -0700 | [diff] [blame] | 988 | * <p></p>Return a list of the tasks that the user has recently launched, with |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 989 | * the most recent being first and older ones after in order. |
Dianne Hackborn | c5bf758 | 2012-04-25 19:12:07 -0700 | [diff] [blame] | 990 | * |
| 991 | * <p><b>Note: this method is only intended for debugging and presenting |
| 992 | * task management user interfaces</b>. This should never be used for |
| 993 | * core logic in an application, such as deciding between different |
| 994 | * behaviors based on the information found here. Such uses are |
| 995 | * <em>not</em> supported, and will likely break in the future. For |
| 996 | * example, if multiple applications can be actively running at the |
| 997 | * same time, assumptions made about the meaning of the data here for |
| 998 | * purposes of control flow will be incorrect.</p> |
| 999 | * |
Dianne Hackborn | 955d8d6 | 2014-10-07 20:17:19 -0700 | [diff] [blame] | 1000 | * @deprecated As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method is |
Dianne Hackborn | 2d7576b | 2014-10-03 16:26:04 -0700 | [diff] [blame] | 1001 | * no longer available to third party applications: the introduction of |
Dianne Hackborn | a25a8b2 | 2014-05-30 12:30:35 -0700 | [diff] [blame] | 1002 | * document-centric recents means |
| 1003 | * it can leak personal information to the caller. For backwards compatibility, |
| 1004 | * it will still return a small subset of its data: at least the caller's |
| 1005 | * own tasks (though see {@link #getAppTasks()} for the correct supported |
| 1006 | * way to retrieve that information), and possibly some other tasks |
| 1007 | * such as home that are known to not be sensitive. |
| 1008 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1009 | * @param maxNum The maximum number of entries to return in the list. The |
| 1010 | * actual number returned may be smaller, depending on how many tasks the |
| 1011 | * user has started and the maximum number the system can remember. |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 1012 | * @param flags Information about what to return. May be any combination |
Dianne Hackborn | 805fd7e | 2011-01-16 18:30:29 -0800 | [diff] [blame] | 1013 | * of {@link #RECENT_WITH_EXCLUDED} and {@link #RECENT_IGNORE_UNAVAILABLE}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1014 | * |
| 1015 | * @return Returns a list of RecentTaskInfo records describing each of |
| 1016 | * the recent tasks. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1017 | */ |
Dianne Hackborn | a25a8b2 | 2014-05-30 12:30:35 -0700 | [diff] [blame] | 1018 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1019 | public List<RecentTaskInfo> getRecentTasks(int maxNum, int flags) |
| 1020 | throws SecurityException { |
| 1021 | try { |
| 1022 | return ActivityManagerNative.getDefault().getRecentTasks(maxNum, |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 1023 | flags, UserHandle.myUserId()); |
Amith Yamasani | 8264408 | 2012-08-03 13:09:11 -0700 | [diff] [blame] | 1024 | } catch (RemoteException e) { |
| 1025 | // System dead, we will be dead too soon! |
| 1026 | return null; |
| 1027 | } |
| 1028 | } |
| 1029 | |
| 1030 | /** |
| 1031 | * Same as {@link #getRecentTasks(int, int)} but returns the recent tasks for a |
| 1032 | * specific user. It requires holding |
| 1033 | * the {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permission. |
| 1034 | * @param maxNum The maximum number of entries to return in the list. The |
| 1035 | * actual number returned may be smaller, depending on how many tasks the |
| 1036 | * user has started and the maximum number the system can remember. |
| 1037 | * @param flags Information about what to return. May be any combination |
| 1038 | * of {@link #RECENT_WITH_EXCLUDED} and {@link #RECENT_IGNORE_UNAVAILABLE}. |
| 1039 | * |
| 1040 | * @return Returns a list of RecentTaskInfo records describing each of |
| 1041 | * the recent tasks. |
| 1042 | * |
Amith Yamasani | 8264408 | 2012-08-03 13:09:11 -0700 | [diff] [blame] | 1043 | * @hide |
| 1044 | */ |
| 1045 | public List<RecentTaskInfo> getRecentTasksForUser(int maxNum, int flags, int userId) |
| 1046 | throws SecurityException { |
| 1047 | try { |
| 1048 | return ActivityManagerNative.getDefault().getRecentTasks(maxNum, |
| 1049 | flags, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1050 | } catch (RemoteException e) { |
| 1051 | // System dead, we will be dead too soon! |
| 1052 | return null; |
| 1053 | } |
| 1054 | } |
| 1055 | |
| 1056 | /** |
| 1057 | * Information you can retrieve about a particular task that is currently |
| 1058 | * "running" in the system. Note that a running task does not mean the |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 1059 | * given task actually has a process it is actively running in; it simply |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1060 | * means that the user has gone to it and never closed it, but currently |
| 1061 | * the system may have killed its process and is only holding on to its |
| 1062 | * last state in order to restart it when the user returns. |
| 1063 | */ |
| 1064 | public static class RunningTaskInfo implements Parcelable { |
| 1065 | /** |
| 1066 | * A unique identifier for this task. |
| 1067 | */ |
| 1068 | public int id; |
| 1069 | |
| 1070 | /** |
| 1071 | * The component launched as the first activity in the task. This can |
| 1072 | * be considered the "application" of this task. |
| 1073 | */ |
| 1074 | public ComponentName baseActivity; |
| 1075 | |
| 1076 | /** |
| 1077 | * The activity component at the top of the history stack of the task. |
| 1078 | * This is what the user is currently doing. |
| 1079 | */ |
| 1080 | public ComponentName topActivity; |
| 1081 | |
| 1082 | /** |
Dianne Hackborn | 805fd7e | 2011-01-16 18:30:29 -0800 | [diff] [blame] | 1083 | * Thumbnail representation of the task's current state. Currently |
| 1084 | * always null. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1085 | */ |
| 1086 | public Bitmap thumbnail; |
| 1087 | |
| 1088 | /** |
| 1089 | * Description of the task's current state. |
| 1090 | */ |
| 1091 | public CharSequence description; |
| 1092 | |
| 1093 | /** |
| 1094 | * Number of activities in this task. |
| 1095 | */ |
| 1096 | public int numActivities; |
| 1097 | |
| 1098 | /** |
| 1099 | * Number of activities that are currently running (not stopped |
| 1100 | * and persisted) in this task. |
| 1101 | */ |
| 1102 | public int numRunning; |
| 1103 | |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 1104 | /** |
| 1105 | * Last time task was run. For sorting. |
| 1106 | * @hide |
| 1107 | */ |
| 1108 | public long lastActiveTime; |
| 1109 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1110 | public RunningTaskInfo() { |
| 1111 | } |
| 1112 | |
| 1113 | public int describeContents() { |
| 1114 | return 0; |
| 1115 | } |
| 1116 | |
| 1117 | public void writeToParcel(Parcel dest, int flags) { |
| 1118 | dest.writeInt(id); |
| 1119 | ComponentName.writeToParcel(baseActivity, dest); |
| 1120 | ComponentName.writeToParcel(topActivity, dest); |
| 1121 | if (thumbnail != null) { |
| 1122 | dest.writeInt(1); |
| 1123 | thumbnail.writeToParcel(dest, 0); |
| 1124 | } else { |
| 1125 | dest.writeInt(0); |
| 1126 | } |
| 1127 | TextUtils.writeToParcel(description, dest, |
| 1128 | Parcelable.PARCELABLE_WRITE_RETURN_VALUE); |
| 1129 | dest.writeInt(numActivities); |
| 1130 | dest.writeInt(numRunning); |
| 1131 | } |
| 1132 | |
| 1133 | public void readFromParcel(Parcel source) { |
| 1134 | id = source.readInt(); |
| 1135 | baseActivity = ComponentName.readFromParcel(source); |
| 1136 | topActivity = ComponentName.readFromParcel(source); |
| 1137 | if (source.readInt() != 0) { |
| 1138 | thumbnail = Bitmap.CREATOR.createFromParcel(source); |
| 1139 | } else { |
| 1140 | thumbnail = null; |
| 1141 | } |
| 1142 | description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); |
| 1143 | numActivities = source.readInt(); |
| 1144 | numRunning = source.readInt(); |
| 1145 | } |
| 1146 | |
| 1147 | public static final Creator<RunningTaskInfo> CREATOR = new Creator<RunningTaskInfo>() { |
| 1148 | public RunningTaskInfo createFromParcel(Parcel source) { |
| 1149 | return new RunningTaskInfo(source); |
| 1150 | } |
| 1151 | public RunningTaskInfo[] newArray(int size) { |
| 1152 | return new RunningTaskInfo[size]; |
| 1153 | } |
| 1154 | }; |
| 1155 | |
| 1156 | private RunningTaskInfo(Parcel source) { |
| 1157 | readFromParcel(source); |
| 1158 | } |
| 1159 | } |
Winson Chung | 1147c40 | 2014-05-14 11:05:00 -0700 | [diff] [blame] | 1160 | |
| 1161 | /** |
| 1162 | * Get the list of tasks associated with the calling application. |
| 1163 | * |
| 1164 | * @return The list of tasks associated with the application making this call. |
| 1165 | * @throws SecurityException |
| 1166 | */ |
| 1167 | public List<ActivityManager.AppTask> getAppTasks() { |
| 1168 | ArrayList<AppTask> tasks = new ArrayList<AppTask>(); |
| 1169 | List<IAppTask> appTasks; |
| 1170 | try { |
Dianne Hackborn | 885fbe5 | 2014-08-23 15:23:58 -0700 | [diff] [blame] | 1171 | appTasks = ActivityManagerNative.getDefault().getAppTasks(mContext.getPackageName()); |
Winson Chung | 1147c40 | 2014-05-14 11:05:00 -0700 | [diff] [blame] | 1172 | } catch (RemoteException e) { |
| 1173 | // System dead, we will be dead too soon! |
| 1174 | return null; |
| 1175 | } |
| 1176 | int numAppTasks = appTasks.size(); |
| 1177 | for (int i = 0; i < numAppTasks; i++) { |
| 1178 | tasks.add(new AppTask(appTasks.get(i))); |
| 1179 | } |
| 1180 | return tasks; |
| 1181 | } |
| 1182 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1183 | /** |
Winson Chung | 48a10a5 | 2014-08-27 14:36:51 -0700 | [diff] [blame] | 1184 | * Return the current design dimensions for {@link AppTask} thumbnails, for use |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 1185 | * with {@link #addAppTask}. |
| 1186 | */ |
Winson Chung | 48a10a5 | 2014-08-27 14:36:51 -0700 | [diff] [blame] | 1187 | public Size getAppTaskThumbnailSize() { |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 1188 | synchronized (this) { |
| 1189 | ensureAppTaskThumbnailSizeLocked(); |
Winson Chung | 48a10a5 | 2014-08-27 14:36:51 -0700 | [diff] [blame] | 1190 | return new Size(mAppTaskThumbnailSize.x, mAppTaskThumbnailSize.y); |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 1191 | } |
| 1192 | } |
| 1193 | |
| 1194 | private void ensureAppTaskThumbnailSizeLocked() { |
| 1195 | if (mAppTaskThumbnailSize == null) { |
| 1196 | try { |
| 1197 | mAppTaskThumbnailSize = ActivityManagerNative.getDefault().getAppTaskThumbnailSize(); |
| 1198 | } catch (RemoteException e) { |
| 1199 | throw new IllegalStateException("System dead?", e); |
| 1200 | } |
| 1201 | } |
| 1202 | } |
| 1203 | |
| 1204 | /** |
| 1205 | * Add a new {@link AppTask} for the calling application. This will create a new |
| 1206 | * recents entry that is added to the <b>end</b> of all existing recents. |
| 1207 | * |
| 1208 | * @param activity The activity that is adding the entry. This is used to help determine |
| 1209 | * the context that the new recents entry will be in. |
| 1210 | * @param intent The Intent that describes the recents entry. This is the same Intent that |
| 1211 | * you would have used to launch the activity for it. In generally you will want to set |
| 1212 | * both {@link Intent#FLAG_ACTIVITY_NEW_DOCUMENT} and |
| 1213 | * {@link Intent#FLAG_ACTIVITY_RETAIN_IN_RECENTS}; the latter is required since this recents |
| 1214 | * entry will exist without an activity, so it doesn't make sense to not retain it when |
| 1215 | * its activity disappears. The given Intent here also must have an explicit ComponentName |
| 1216 | * set on it. |
| 1217 | * @param description Optional additional description information. |
| 1218 | * @param thumbnail Thumbnail to use for the recents entry. Should be the size given by |
Winson Chung | 48a10a5 | 2014-08-27 14:36:51 -0700 | [diff] [blame] | 1219 | * {@link #getAppTaskThumbnailSize()}. If the bitmap is not that exact size, it will be |
| 1220 | * recreated in your process, probably in a way you don't like, before the recents entry |
| 1221 | * is added. |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 1222 | * |
| 1223 | * @return Returns the task id of the newly added app task, or -1 if the add failed. The |
| 1224 | * most likely cause of failure is that there is no more room for more tasks for your app. |
| 1225 | */ |
| 1226 | public int addAppTask(@NonNull Activity activity, @NonNull Intent intent, |
| 1227 | @Nullable TaskDescription description, @NonNull Bitmap thumbnail) { |
| 1228 | Point size; |
| 1229 | synchronized (this) { |
| 1230 | ensureAppTaskThumbnailSizeLocked(); |
| 1231 | size = mAppTaskThumbnailSize; |
| 1232 | } |
| 1233 | final int tw = thumbnail.getWidth(); |
| 1234 | final int th = thumbnail.getHeight(); |
| 1235 | if (tw != size.x || th != size.y) { |
| 1236 | Bitmap bm = Bitmap.createBitmap(size.x, size.y, thumbnail.getConfig()); |
| 1237 | |
| 1238 | // Use ScaleType.CENTER_CROP, except we leave the top edge at the top. |
| 1239 | float scale; |
| 1240 | float dx = 0, dy = 0; |
| 1241 | if (tw * size.x > size.y * th) { |
| 1242 | scale = (float) size.x / (float) th; |
| 1243 | dx = (size.y - tw * scale) * 0.5f; |
| 1244 | } else { |
| 1245 | scale = (float) size.y / (float) tw; |
| 1246 | dy = (size.x - th * scale) * 0.5f; |
| 1247 | } |
| 1248 | Matrix matrix = new Matrix(); |
| 1249 | matrix.setScale(scale, scale); |
| 1250 | matrix.postTranslate((int) (dx + 0.5f), 0); |
| 1251 | |
| 1252 | Canvas canvas = new Canvas(bm); |
| 1253 | canvas.drawBitmap(thumbnail, matrix, null); |
| 1254 | canvas.setBitmap(null); |
| 1255 | |
| 1256 | thumbnail = bm; |
| 1257 | } |
| 1258 | if (description == null) { |
| 1259 | description = new TaskDescription(); |
| 1260 | } |
| 1261 | try { |
| 1262 | return ActivityManagerNative.getDefault().addAppTask(activity.getActivityToken(), |
| 1263 | intent, description, thumbnail); |
| 1264 | } catch (RemoteException e) { |
| 1265 | throw new IllegalStateException("System dead?", e); |
| 1266 | } |
| 1267 | } |
| 1268 | |
| 1269 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1270 | * Return a list of the tasks that are currently running, with |
| 1271 | * the most recent being first and older ones after in order. Note that |
| 1272 | * "running" does not mean any of the task's code is currently loaded or |
| 1273 | * activity -- the task may have been frozen by the system, so that it |
| 1274 | * can be restarted in its previous state when next brought to the |
| 1275 | * foreground. |
Jim Miller | 0b2a6d0 | 2010-07-13 18:01:29 -0700 | [diff] [blame] | 1276 | * |
Dianne Hackborn | c5bf758 | 2012-04-25 19:12:07 -0700 | [diff] [blame] | 1277 | * <p><b>Note: this method is only intended for debugging and presenting |
| 1278 | * task management user interfaces</b>. This should never be used for |
| 1279 | * core logic in an application, such as deciding between different |
| 1280 | * behaviors based on the information found here. Such uses are |
| 1281 | * <em>not</em> supported, and will likely break in the future. For |
| 1282 | * example, if multiple applications can be actively running at the |
| 1283 | * same time, assumptions made about the meaning of the data here for |
| 1284 | * purposes of control flow will be incorrect.</p> |
| 1285 | * |
Dianne Hackborn | 955d8d6 | 2014-10-07 20:17:19 -0700 | [diff] [blame] | 1286 | * @deprecated As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method |
Dianne Hackborn | a25a8b2 | 2014-05-30 12:30:35 -0700 | [diff] [blame] | 1287 | * is no longer available to third party |
| 1288 | * applications: the introduction of document-centric recents means |
| 1289 | * it can leak person information to the caller. For backwards compatibility, |
| 1290 | * it will still retu rn a small subset of its data: at least the caller's |
| 1291 | * own tasks, and possibly some other tasks |
| 1292 | * such as home that are known to not be sensitive. |
| 1293 | * |
Jim Miller | 0b2a6d0 | 2010-07-13 18:01:29 -0700 | [diff] [blame] | 1294 | * @param maxNum The maximum number of entries to return in the list. The |
| 1295 | * actual number returned may be smaller, depending on how many tasks the |
| 1296 | * user has started. |
| 1297 | * |
| 1298 | * @return Returns a list of RunningTaskInfo records describing each of |
| 1299 | * the running tasks. |
Jim Miller | 0b2a6d0 | 2010-07-13 18:01:29 -0700 | [diff] [blame] | 1300 | */ |
Dianne Hackborn | a25a8b2 | 2014-05-30 12:30:35 -0700 | [diff] [blame] | 1301 | @Deprecated |
Jim Miller | 0b2a6d0 | 2010-07-13 18:01:29 -0700 | [diff] [blame] | 1302 | public List<RunningTaskInfo> getRunningTasks(int maxNum) |
| 1303 | throws SecurityException { |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 1304 | try { |
| 1305 | return ActivityManagerNative.getDefault().getTasks(maxNum, 0); |
| 1306 | } catch (RemoteException e) { |
| 1307 | // System dead, we will be dead too soon! |
| 1308 | return null; |
| 1309 | } |
Jim Miller | 0b2a6d0 | 2010-07-13 18:01:29 -0700 | [diff] [blame] | 1310 | } |
| 1311 | |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 1312 | /** |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 1313 | * Completely remove the given task. |
| 1314 | * |
| 1315 | * @param taskId Identifier of the task to be removed. |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 1316 | * @return Returns true if the given task was found and removed. |
| 1317 | * |
| 1318 | * @hide |
| 1319 | */ |
Wale Ogunwale | d54b578 | 2014-10-23 15:55:23 -0700 | [diff] [blame] | 1320 | public boolean removeTask(int taskId) throws SecurityException { |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 1321 | try { |
Wale Ogunwale | d54b578 | 2014-10-23 15:55:23 -0700 | [diff] [blame] | 1322 | return ActivityManagerNative.getDefault().removeTask(taskId); |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 1323 | } catch (RemoteException e) { |
| 1324 | // System dead, we will be dead too soon! |
| 1325 | return false; |
| 1326 | } |
| 1327 | } |
| 1328 | |
Dianne Hackborn | d94df45 | 2011-02-16 18:53:31 -0800 | [diff] [blame] | 1329 | /** @hide */ |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 1330 | public static class TaskThumbnail implements Parcelable { |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 1331 | public Bitmap mainThumbnail; |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 1332 | public ParcelFileDescriptor thumbnailFileDescriptor; |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 1333 | |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 1334 | public TaskThumbnail() { |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 1335 | } |
| 1336 | |
| 1337 | public int describeContents() { |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 1338 | if (thumbnailFileDescriptor != null) { |
| 1339 | return thumbnailFileDescriptor.describeContents(); |
| 1340 | } |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 1341 | return 0; |
| 1342 | } |
| 1343 | |
| 1344 | public void writeToParcel(Parcel dest, int flags) { |
| 1345 | if (mainThumbnail != null) { |
| 1346 | dest.writeInt(1); |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 1347 | mainThumbnail.writeToParcel(dest, flags); |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 1348 | } else { |
| 1349 | dest.writeInt(0); |
| 1350 | } |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 1351 | if (thumbnailFileDescriptor != null) { |
| 1352 | dest.writeInt(1); |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 1353 | thumbnailFileDescriptor.writeToParcel(dest, flags); |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 1354 | } else { |
| 1355 | dest.writeInt(0); |
| 1356 | } |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 1357 | } |
| 1358 | |
| 1359 | public void readFromParcel(Parcel source) { |
| 1360 | if (source.readInt() != 0) { |
| 1361 | mainThumbnail = Bitmap.CREATOR.createFromParcel(source); |
| 1362 | } else { |
| 1363 | mainThumbnail = null; |
| 1364 | } |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 1365 | if (source.readInt() != 0) { |
| 1366 | thumbnailFileDescriptor = ParcelFileDescriptor.CREATOR.createFromParcel(source); |
| 1367 | } else { |
| 1368 | thumbnailFileDescriptor = null; |
| 1369 | } |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 1370 | } |
| 1371 | |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 1372 | public static final Creator<TaskThumbnail> CREATOR = new Creator<TaskThumbnail>() { |
| 1373 | public TaskThumbnail createFromParcel(Parcel source) { |
| 1374 | return new TaskThumbnail(source); |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 1375 | } |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 1376 | public TaskThumbnail[] newArray(int size) { |
| 1377 | return new TaskThumbnail[size]; |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 1378 | } |
| 1379 | }; |
| 1380 | |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 1381 | private TaskThumbnail(Parcel source) { |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 1382 | readFromParcel(source); |
| 1383 | } |
| 1384 | } |
| 1385 | |
| 1386 | /** @hide */ |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 1387 | public TaskThumbnail getTaskThumbnail(int id) throws SecurityException { |
Dianne Hackborn | d94df45 | 2011-02-16 18:53:31 -0800 | [diff] [blame] | 1388 | try { |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 1389 | return ActivityManagerNative.getDefault().getTaskThumbnail(id); |
Dianne Hackborn | 15491c6 | 2012-09-19 10:59:14 -0700 | [diff] [blame] | 1390 | } catch (RemoteException e) { |
| 1391 | // System dead, we will be dead too soon! |
| 1392 | return null; |
| 1393 | } |
| 1394 | } |
| 1395 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 1396 | /** @hide */ |
| 1397 | public boolean isInHomeStack(int taskId) { |
| 1398 | try { |
| 1399 | return ActivityManagerNative.getDefault().isInHomeStack(taskId); |
| 1400 | } catch (RemoteException e) { |
| 1401 | // System dead, we will be dead too soon! |
| 1402 | return false; |
| 1403 | } |
| 1404 | } |
| 1405 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1406 | /** |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 1407 | * Flag for {@link #moveTaskToFront(int, int)}: also move the "home" |
| 1408 | * activity along with the task, so it is positioned immediately behind |
| 1409 | * the task. |
| 1410 | */ |
| 1411 | public static final int MOVE_TASK_WITH_HOME = 0x00000001; |
| 1412 | |
| 1413 | /** |
Dianne Hackborn | d94df45 | 2011-02-16 18:53:31 -0800 | [diff] [blame] | 1414 | * Flag for {@link #moveTaskToFront(int, int)}: don't count this as a |
| 1415 | * user-instigated action, so the current activity will not receive a |
| 1416 | * hint that the user is leaving. |
| 1417 | */ |
| 1418 | public static final int MOVE_TASK_NO_USER_ACTION = 0x00000002; |
| 1419 | |
| 1420 | /** |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1421 | * Equivalent to calling {@link #moveTaskToFront(int, int, Bundle)} |
| 1422 | * with a null options argument. |
| 1423 | * |
| 1424 | * @param taskId The identifier of the task to be moved, as found in |
| 1425 | * {@link RunningTaskInfo} or {@link RecentTaskInfo}. |
| 1426 | * @param flags Additional operational flags, 0 or more of |
Craig Mautner | ecbfe25 | 2013-03-28 11:58:25 -0700 | [diff] [blame] | 1427 | * {@link #MOVE_TASK_WITH_HOME}, {@link #MOVE_TASK_NO_USER_ACTION}. |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1428 | */ |
| 1429 | public void moveTaskToFront(int taskId, int flags) { |
| 1430 | moveTaskToFront(taskId, flags, null); |
| 1431 | } |
| 1432 | |
| 1433 | /** |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 1434 | * Ask that the task associated with a given task ID be moved to the |
| 1435 | * front of the stack, so it is now visible to the user. Requires that |
| 1436 | * the caller hold permission {@link android.Manifest.permission#REORDER_TASKS} |
| 1437 | * or a SecurityException will be thrown. |
| 1438 | * |
| 1439 | * @param taskId The identifier of the task to be moved, as found in |
| 1440 | * {@link RunningTaskInfo} or {@link RecentTaskInfo}. |
| 1441 | * @param flags Additional operational flags, 0 or more of |
Craig Mautner | ecbfe25 | 2013-03-28 11:58:25 -0700 | [diff] [blame] | 1442 | * {@link #MOVE_TASK_WITH_HOME}, {@link #MOVE_TASK_NO_USER_ACTION}. |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1443 | * @param options Additional options for the operation, either null or |
| 1444 | * as per {@link Context#startActivity(Intent, android.os.Bundle) |
| 1445 | * Context.startActivity(Intent, Bundle)}. |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 1446 | */ |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1447 | public void moveTaskToFront(int taskId, int flags, Bundle options) { |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 1448 | try { |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1449 | ActivityManagerNative.getDefault().moveTaskToFront(taskId, flags, options); |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 1450 | } catch (RemoteException e) { |
| 1451 | // System dead, we will be dead too soon! |
| 1452 | } |
| 1453 | } |
| 1454 | |
| 1455 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1456 | * Information you can retrieve about a particular Service that is |
| 1457 | * currently running in the system. |
| 1458 | */ |
| 1459 | public static class RunningServiceInfo implements Parcelable { |
| 1460 | /** |
| 1461 | * The service component. |
| 1462 | */ |
| 1463 | public ComponentName service; |
| 1464 | |
| 1465 | /** |
| 1466 | * If non-zero, this is the process the service is running in. |
| 1467 | */ |
| 1468 | public int pid; |
| 1469 | |
| 1470 | /** |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 1471 | * The UID that owns this service. |
| 1472 | */ |
| 1473 | public int uid; |
| 1474 | |
| 1475 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1476 | * The name of the process this service runs in. |
| 1477 | */ |
| 1478 | public String process; |
| 1479 | |
| 1480 | /** |
| 1481 | * Set to true if the service has asked to run as a foreground process. |
| 1482 | */ |
| 1483 | public boolean foreground; |
| 1484 | |
| 1485 | /** |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 1486 | * The time when the service was first made active, either by someone |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1487 | * starting or binding to it. This |
| 1488 | * is in units of {@link android.os.SystemClock#elapsedRealtime()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1489 | */ |
| 1490 | public long activeSince; |
| 1491 | |
| 1492 | /** |
| 1493 | * Set to true if this service has been explicitly started. |
| 1494 | */ |
| 1495 | public boolean started; |
| 1496 | |
| 1497 | /** |
| 1498 | * Number of clients connected to the service. |
| 1499 | */ |
| 1500 | public int clientCount; |
| 1501 | |
| 1502 | /** |
| 1503 | * Number of times the service's process has crashed while the service |
| 1504 | * is running. |
| 1505 | */ |
| 1506 | public int crashCount; |
| 1507 | |
| 1508 | /** |
| 1509 | * The time when there was last activity in the service (either |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1510 | * explicit requests to start it or clients binding to it). This |
| 1511 | * is in units of {@link android.os.SystemClock#uptimeMillis()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1512 | */ |
| 1513 | public long lastActivityTime; |
| 1514 | |
| 1515 | /** |
| 1516 | * If non-zero, this service is not currently running, but scheduled to |
| 1517 | * restart at the given time. |
| 1518 | */ |
| 1519 | public long restarting; |
| 1520 | |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 1521 | /** |
| 1522 | * Bit for {@link #flags}: set if this service has been |
| 1523 | * explicitly started. |
| 1524 | */ |
| 1525 | public static final int FLAG_STARTED = 1<<0; |
| 1526 | |
| 1527 | /** |
| 1528 | * Bit for {@link #flags}: set if the service has asked to |
| 1529 | * run as a foreground process. |
| 1530 | */ |
| 1531 | public static final int FLAG_FOREGROUND = 1<<1; |
| 1532 | |
| 1533 | /** |
| 1534 | * Bit for {@link #flags): set if the service is running in a |
| 1535 | * core system process. |
| 1536 | */ |
| 1537 | public static final int FLAG_SYSTEM_PROCESS = 1<<2; |
| 1538 | |
| 1539 | /** |
| 1540 | * Bit for {@link #flags): set if the service is running in a |
| 1541 | * persistent process. |
| 1542 | */ |
| 1543 | public static final int FLAG_PERSISTENT_PROCESS = 1<<3; |
| 1544 | |
| 1545 | /** |
| 1546 | * Running flags. |
| 1547 | */ |
| 1548 | public int flags; |
| 1549 | |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 1550 | /** |
| 1551 | * For special services that are bound to by system code, this is |
| 1552 | * the package that holds the binding. |
| 1553 | */ |
| 1554 | public String clientPackage; |
| 1555 | |
| 1556 | /** |
| 1557 | * For special services that are bound to by system code, this is |
| 1558 | * a string resource providing a user-visible label for who the |
| 1559 | * client is. |
| 1560 | */ |
| 1561 | public int clientLabel; |
| 1562 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1563 | public RunningServiceInfo() { |
| 1564 | } |
| 1565 | |
| 1566 | public int describeContents() { |
| 1567 | return 0; |
| 1568 | } |
| 1569 | |
| 1570 | public void writeToParcel(Parcel dest, int flags) { |
| 1571 | ComponentName.writeToParcel(service, dest); |
| 1572 | dest.writeInt(pid); |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 1573 | dest.writeInt(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1574 | dest.writeString(process); |
| 1575 | dest.writeInt(foreground ? 1 : 0); |
| 1576 | dest.writeLong(activeSince); |
| 1577 | dest.writeInt(started ? 1 : 0); |
| 1578 | dest.writeInt(clientCount); |
| 1579 | dest.writeInt(crashCount); |
| 1580 | dest.writeLong(lastActivityTime); |
| 1581 | dest.writeLong(restarting); |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 1582 | dest.writeInt(this.flags); |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 1583 | dest.writeString(clientPackage); |
| 1584 | dest.writeInt(clientLabel); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1585 | } |
| 1586 | |
| 1587 | public void readFromParcel(Parcel source) { |
| 1588 | service = ComponentName.readFromParcel(source); |
| 1589 | pid = source.readInt(); |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 1590 | uid = source.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1591 | process = source.readString(); |
| 1592 | foreground = source.readInt() != 0; |
| 1593 | activeSince = source.readLong(); |
| 1594 | started = source.readInt() != 0; |
| 1595 | clientCount = source.readInt(); |
| 1596 | crashCount = source.readInt(); |
| 1597 | lastActivityTime = source.readLong(); |
| 1598 | restarting = source.readLong(); |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 1599 | flags = source.readInt(); |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 1600 | clientPackage = source.readString(); |
| 1601 | clientLabel = source.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1602 | } |
| 1603 | |
| 1604 | public static final Creator<RunningServiceInfo> CREATOR = new Creator<RunningServiceInfo>() { |
| 1605 | public RunningServiceInfo createFromParcel(Parcel source) { |
| 1606 | return new RunningServiceInfo(source); |
| 1607 | } |
| 1608 | public RunningServiceInfo[] newArray(int size) { |
| 1609 | return new RunningServiceInfo[size]; |
| 1610 | } |
| 1611 | }; |
| 1612 | |
| 1613 | private RunningServiceInfo(Parcel source) { |
| 1614 | readFromParcel(source); |
| 1615 | } |
| 1616 | } |
| 1617 | |
| 1618 | /** |
| 1619 | * Return a list of the services that are currently running. |
Dianne Hackborn | c5bf758 | 2012-04-25 19:12:07 -0700 | [diff] [blame] | 1620 | * |
| 1621 | * <p><b>Note: this method is only intended for debugging or implementing |
| 1622 | * service management type user interfaces.</b></p> |
| 1623 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1624 | * @param maxNum The maximum number of entries to return in the list. The |
| 1625 | * actual number returned may be smaller, depending on how many services |
| 1626 | * are running. |
| 1627 | * |
| 1628 | * @return Returns a list of RunningServiceInfo records describing each of |
| 1629 | * the running tasks. |
| 1630 | */ |
| 1631 | public List<RunningServiceInfo> getRunningServices(int maxNum) |
| 1632 | throws SecurityException { |
| 1633 | try { |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 1634 | return ActivityManagerNative.getDefault() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1635 | .getServices(maxNum, 0); |
| 1636 | } catch (RemoteException e) { |
| 1637 | // System dead, we will be dead too soon! |
| 1638 | return null; |
| 1639 | } |
| 1640 | } |
| 1641 | |
| 1642 | /** |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 1643 | * Returns a PendingIntent you can start to show a control panel for the |
| 1644 | * given running service. If the service does not have a control panel, |
| 1645 | * null is returned. |
| 1646 | */ |
| 1647 | public PendingIntent getRunningServiceControlPanel(ComponentName service) |
| 1648 | throws SecurityException { |
| 1649 | try { |
| 1650 | return ActivityManagerNative.getDefault() |
| 1651 | .getRunningServiceControlPanel(service); |
| 1652 | } catch (RemoteException e) { |
| 1653 | // System dead, we will be dead too soon! |
| 1654 | return null; |
| 1655 | } |
| 1656 | } |
| 1657 | |
| 1658 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1659 | * Information you can retrieve about the available memory through |
| 1660 | * {@link ActivityManager#getMemoryInfo}. |
| 1661 | */ |
| 1662 | public static class MemoryInfo implements Parcelable { |
| 1663 | /** |
Dianne Hackborn | 59325eb | 2012-05-09 18:45:20 -0700 | [diff] [blame] | 1664 | * The available memory on the system. This number should not |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1665 | * be considered absolute: due to the nature of the kernel, a significant |
| 1666 | * portion of this memory is actually in use and needed for the overall |
| 1667 | * system to run well. |
| 1668 | */ |
| 1669 | public long availMem; |
Dianne Hackborn | 59325eb | 2012-05-09 18:45:20 -0700 | [diff] [blame] | 1670 | |
| 1671 | /** |
| 1672 | * The total memory accessible by the kernel. This is basically the |
| 1673 | * RAM size of the device, not including below-kernel fixed allocations |
| 1674 | * like DMA buffers, RAM for the baseband CPU, etc. |
| 1675 | */ |
| 1676 | public long totalMem; |
| 1677 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1678 | /** |
| 1679 | * The threshold of {@link #availMem} at which we consider memory to be |
| 1680 | * low and start killing background services and other non-extraneous |
| 1681 | * processes. |
| 1682 | */ |
| 1683 | public long threshold; |
| 1684 | |
| 1685 | /** |
| 1686 | * Set to true if the system considers itself to currently be in a low |
| 1687 | * memory situation. |
| 1688 | */ |
| 1689 | public boolean lowMemory; |
| 1690 | |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 1691 | /** @hide */ |
| 1692 | public long hiddenAppThreshold; |
| 1693 | /** @hide */ |
| 1694 | public long secondaryServerThreshold; |
| 1695 | /** @hide */ |
| 1696 | public long visibleAppThreshold; |
| 1697 | /** @hide */ |
| 1698 | public long foregroundAppThreshold; |
| 1699 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1700 | public MemoryInfo() { |
| 1701 | } |
| 1702 | |
| 1703 | public int describeContents() { |
| 1704 | return 0; |
| 1705 | } |
| 1706 | |
| 1707 | public void writeToParcel(Parcel dest, int flags) { |
| 1708 | dest.writeLong(availMem); |
Dianne Hackborn | 59325eb | 2012-05-09 18:45:20 -0700 | [diff] [blame] | 1709 | dest.writeLong(totalMem); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1710 | dest.writeLong(threshold); |
| 1711 | dest.writeInt(lowMemory ? 1 : 0); |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 1712 | dest.writeLong(hiddenAppThreshold); |
| 1713 | dest.writeLong(secondaryServerThreshold); |
| 1714 | dest.writeLong(visibleAppThreshold); |
| 1715 | dest.writeLong(foregroundAppThreshold); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1716 | } |
| 1717 | |
| 1718 | public void readFromParcel(Parcel source) { |
| 1719 | availMem = source.readLong(); |
Dianne Hackborn | 59325eb | 2012-05-09 18:45:20 -0700 | [diff] [blame] | 1720 | totalMem = source.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1721 | threshold = source.readLong(); |
| 1722 | lowMemory = source.readInt() != 0; |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 1723 | hiddenAppThreshold = source.readLong(); |
| 1724 | secondaryServerThreshold = source.readLong(); |
| 1725 | visibleAppThreshold = source.readLong(); |
| 1726 | foregroundAppThreshold = source.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1727 | } |
| 1728 | |
| 1729 | public static final Creator<MemoryInfo> CREATOR |
| 1730 | = new Creator<MemoryInfo>() { |
| 1731 | public MemoryInfo createFromParcel(Parcel source) { |
| 1732 | return new MemoryInfo(source); |
| 1733 | } |
| 1734 | public MemoryInfo[] newArray(int size) { |
| 1735 | return new MemoryInfo[size]; |
| 1736 | } |
| 1737 | }; |
| 1738 | |
| 1739 | private MemoryInfo(Parcel source) { |
| 1740 | readFromParcel(source); |
| 1741 | } |
| 1742 | } |
| 1743 | |
Dianne Hackborn | c5bf758 | 2012-04-25 19:12:07 -0700 | [diff] [blame] | 1744 | /** |
| 1745 | * Return general information about the memory state of the system. This |
| 1746 | * can be used to help decide how to manage your own memory, though note |
| 1747 | * that polling is not recommended and |
| 1748 | * {@link android.content.ComponentCallbacks2#onTrimMemory(int) |
| 1749 | * ComponentCallbacks2.onTrimMemory(int)} is the preferred way to do this. |
| 1750 | * Also see {@link #getMyMemoryState} for how to retrieve the current trim |
| 1751 | * level of your process as needed, which gives a better hint for how to |
| 1752 | * manage its memory. |
| 1753 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1754 | public void getMemoryInfo(MemoryInfo outInfo) { |
| 1755 | try { |
| 1756 | ActivityManagerNative.getDefault().getMemoryInfo(outInfo); |
| 1757 | } catch (RemoteException e) { |
| 1758 | } |
| 1759 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1760 | |
Craig Mautner | 5ff1210 | 2013-05-24 12:50:15 -0700 | [diff] [blame] | 1761 | /** |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1762 | * Information you can retrieve about an ActivityStack in the system. |
| 1763 | * @hide |
| 1764 | */ |
| 1765 | public static class StackInfo implements Parcelable { |
| 1766 | public int stackId; |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 1767 | public Rect bounds = new Rect(); |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1768 | public int[] taskIds; |
| 1769 | public String[] taskNames; |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 1770 | public int displayId; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1771 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1772 | @Override |
| 1773 | public int describeContents() { |
| 1774 | return 0; |
| 1775 | } |
| 1776 | |
| 1777 | @Override |
| 1778 | public void writeToParcel(Parcel dest, int flags) { |
| 1779 | dest.writeInt(stackId); |
| 1780 | dest.writeInt(bounds.left); |
| 1781 | dest.writeInt(bounds.top); |
| 1782 | dest.writeInt(bounds.right); |
| 1783 | dest.writeInt(bounds.bottom); |
| 1784 | dest.writeIntArray(taskIds); |
| 1785 | dest.writeStringArray(taskNames); |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 1786 | dest.writeInt(displayId); |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1787 | } |
| 1788 | |
| 1789 | public void readFromParcel(Parcel source) { |
| 1790 | stackId = source.readInt(); |
| 1791 | bounds = new Rect( |
| 1792 | source.readInt(), source.readInt(), source.readInt(), source.readInt()); |
| 1793 | taskIds = source.createIntArray(); |
| 1794 | taskNames = source.createStringArray(); |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 1795 | displayId = source.readInt(); |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1796 | } |
| 1797 | |
| 1798 | public static final Creator<StackInfo> CREATOR = new Creator<StackInfo>() { |
| 1799 | @Override |
| 1800 | public StackInfo createFromParcel(Parcel source) { |
| 1801 | return new StackInfo(source); |
| 1802 | } |
| 1803 | @Override |
| 1804 | public StackInfo[] newArray(int size) { |
| 1805 | return new StackInfo[size]; |
| 1806 | } |
| 1807 | }; |
| 1808 | |
Craig Mautner | 5ff1210 | 2013-05-24 12:50:15 -0700 | [diff] [blame] | 1809 | public StackInfo() { |
| 1810 | } |
| 1811 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1812 | private StackInfo(Parcel source) { |
| 1813 | readFromParcel(source); |
| 1814 | } |
| 1815 | |
Craig Mautner | 5ff1210 | 2013-05-24 12:50:15 -0700 | [diff] [blame] | 1816 | public String toString(String prefix) { |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1817 | StringBuilder sb = new StringBuilder(256); |
Craig Mautner | 5ff1210 | 2013-05-24 12:50:15 -0700 | [diff] [blame] | 1818 | sb.append(prefix); sb.append("Stack id="); sb.append(stackId); |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 1819 | sb.append(" bounds="); sb.append(bounds.toShortString()); |
| 1820 | sb.append(" displayId="); sb.append(displayId); |
| 1821 | sb.append("\n"); |
Craig Mautner | 5ff1210 | 2013-05-24 12:50:15 -0700 | [diff] [blame] | 1822 | prefix = prefix + " "; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1823 | for (int i = 0; i < taskIds.length; ++i) { |
| 1824 | sb.append(prefix); sb.append("taskId="); sb.append(taskIds[i]); |
| 1825 | sb.append(": "); sb.append(taskNames[i]); sb.append("\n"); |
| 1826 | } |
| 1827 | return sb.toString(); |
| 1828 | } |
Craig Mautner | 5ff1210 | 2013-05-24 12:50:15 -0700 | [diff] [blame] | 1829 | |
| 1830 | @Override |
| 1831 | public String toString() { |
| 1832 | return toString(""); |
| 1833 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1834 | } |
| 1835 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1836 | /** |
| 1837 | * @hide |
| 1838 | */ |
| 1839 | public boolean clearApplicationUserData(String packageName, IPackageDataObserver observer) { |
| 1840 | try { |
| 1841 | return ActivityManagerNative.getDefault().clearApplicationUserData(packageName, |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 1842 | observer, UserHandle.myUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1843 | } catch (RemoteException e) { |
| 1844 | return false; |
| 1845 | } |
| 1846 | } |
Christopher Tate | a366424 | 2013-06-26 15:00:18 -0700 | [diff] [blame] | 1847 | |
| 1848 | /** |
| 1849 | * Permits an application to erase its own data from disk. This is equivalent to |
Dianne Hackborn | ebc15ef | 2013-10-09 17:36:57 -0700 | [diff] [blame] | 1850 | * the user choosing to clear the app's data from within the device settings UI. It |
| 1851 | * erases all dynamic data associated with the app -- its private data and data in its |
| 1852 | * private area on external storage -- but does not remove the installed application |
| 1853 | * itself, nor any OBB files. |
Christopher Tate | a366424 | 2013-06-26 15:00:18 -0700 | [diff] [blame] | 1854 | * |
| 1855 | * @return {@code true} if the application successfully requested that the application's |
| 1856 | * data be erased; {@code false} otherwise. |
| 1857 | */ |
| 1858 | public boolean clearApplicationUserData() { |
| 1859 | return clearApplicationUserData(mContext.getPackageName(), null); |
| 1860 | } |
| 1861 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1862 | /** |
| 1863 | * Information you can retrieve about any processes that are in an error condition. |
| 1864 | */ |
| 1865 | public static class ProcessErrorStateInfo implements Parcelable { |
| 1866 | /** |
| 1867 | * Condition codes |
| 1868 | */ |
| 1869 | public static final int NO_ERROR = 0; |
| 1870 | public static final int CRASHED = 1; |
| 1871 | public static final int NOT_RESPONDING = 2; |
| 1872 | |
| 1873 | /** |
| 1874 | * The condition that the process is in. |
| 1875 | */ |
| 1876 | public int condition; |
| 1877 | |
| 1878 | /** |
| 1879 | * The process name in which the crash or error occurred. |
| 1880 | */ |
| 1881 | public String processName; |
| 1882 | |
| 1883 | /** |
| 1884 | * The pid of this process; 0 if none |
| 1885 | */ |
| 1886 | public int pid; |
| 1887 | |
| 1888 | /** |
| 1889 | * The kernel user-ID that has been assigned to this process; |
| 1890 | * currently this is not a unique ID (multiple applications can have |
| 1891 | * the same uid). |
| 1892 | */ |
| 1893 | public int uid; |
| 1894 | |
| 1895 | /** |
Dan Egnor | 60d8762 | 2009-12-16 16:32:58 -0800 | [diff] [blame] | 1896 | * The activity name associated with the error, if known. May be null. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1897 | */ |
| 1898 | public String tag; |
| 1899 | |
| 1900 | /** |
| 1901 | * A short message describing the error condition. |
| 1902 | */ |
| 1903 | public String shortMsg; |
| 1904 | |
| 1905 | /** |
| 1906 | * A long message describing the error condition. |
| 1907 | */ |
| 1908 | public String longMsg; |
| 1909 | |
| 1910 | /** |
Dan Egnor | b7f0367 | 2009-12-09 16:22:32 -0800 | [diff] [blame] | 1911 | * The stack trace where the error originated. May be null. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1912 | */ |
Dan Egnor | b7f0367 | 2009-12-09 16:22:32 -0800 | [diff] [blame] | 1913 | public String stackTrace; |
| 1914 | |
| 1915 | /** |
| 1916 | * to be deprecated: This value will always be null. |
| 1917 | */ |
| 1918 | public byte[] crashData = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1919 | |
| 1920 | public ProcessErrorStateInfo() { |
| 1921 | } |
| 1922 | |
Craig Mautner | 5ff1210 | 2013-05-24 12:50:15 -0700 | [diff] [blame] | 1923 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1924 | public int describeContents() { |
| 1925 | return 0; |
| 1926 | } |
| 1927 | |
Craig Mautner | 5ff1210 | 2013-05-24 12:50:15 -0700 | [diff] [blame] | 1928 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1929 | public void writeToParcel(Parcel dest, int flags) { |
| 1930 | dest.writeInt(condition); |
| 1931 | dest.writeString(processName); |
| 1932 | dest.writeInt(pid); |
| 1933 | dest.writeInt(uid); |
| 1934 | dest.writeString(tag); |
| 1935 | dest.writeString(shortMsg); |
| 1936 | dest.writeString(longMsg); |
Dan Egnor | b7f0367 | 2009-12-09 16:22:32 -0800 | [diff] [blame] | 1937 | dest.writeString(stackTrace); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1938 | } |
Craig Mautner | 5ff1210 | 2013-05-24 12:50:15 -0700 | [diff] [blame] | 1939 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1940 | public void readFromParcel(Parcel source) { |
| 1941 | condition = source.readInt(); |
| 1942 | processName = source.readString(); |
| 1943 | pid = source.readInt(); |
| 1944 | uid = source.readInt(); |
| 1945 | tag = source.readString(); |
| 1946 | shortMsg = source.readString(); |
| 1947 | longMsg = source.readString(); |
Dan Egnor | b7f0367 | 2009-12-09 16:22:32 -0800 | [diff] [blame] | 1948 | stackTrace = source.readString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1949 | } |
| 1950 | |
| 1951 | public static final Creator<ProcessErrorStateInfo> CREATOR = |
| 1952 | new Creator<ProcessErrorStateInfo>() { |
| 1953 | public ProcessErrorStateInfo createFromParcel(Parcel source) { |
| 1954 | return new ProcessErrorStateInfo(source); |
| 1955 | } |
| 1956 | public ProcessErrorStateInfo[] newArray(int size) { |
| 1957 | return new ProcessErrorStateInfo[size]; |
| 1958 | } |
| 1959 | }; |
| 1960 | |
| 1961 | private ProcessErrorStateInfo(Parcel source) { |
| 1962 | readFromParcel(source); |
| 1963 | } |
| 1964 | } |
| 1965 | |
| 1966 | /** |
| 1967 | * Returns a list of any processes that are currently in an error condition. The result |
| 1968 | * will be null if all processes are running properly at this time. |
| 1969 | * |
| 1970 | * @return Returns a list of ProcessErrorStateInfo records, or null if there are no |
| 1971 | * current error conditions (it will not return an empty list). This list ordering is not |
| 1972 | * specified. |
| 1973 | */ |
| 1974 | public List<ProcessErrorStateInfo> getProcessesInErrorState() { |
| 1975 | try { |
| 1976 | return ActivityManagerNative.getDefault().getProcessesInErrorState(); |
| 1977 | } catch (RemoteException e) { |
| 1978 | return null; |
| 1979 | } |
| 1980 | } |
| 1981 | |
| 1982 | /** |
| 1983 | * Information you can retrieve about a running process. |
| 1984 | */ |
| 1985 | public static class RunningAppProcessInfo implements Parcelable { |
| 1986 | /** |
| 1987 | * The name of the process that this object is associated with |
| 1988 | */ |
| 1989 | public String processName; |
| 1990 | |
| 1991 | /** |
| 1992 | * The pid of this process; 0 if none |
| 1993 | */ |
| 1994 | public int pid; |
| 1995 | |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 1996 | /** |
| 1997 | * The user id of this process. |
| 1998 | */ |
| 1999 | public int uid; |
| 2000 | |
Dianne Hackborn | baf42c6 | 2010-06-24 11:23:39 -0700 | [diff] [blame] | 2001 | /** |
| 2002 | * All packages that have been loaded into the process. |
| 2003 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2004 | public String pkgList[]; |
| 2005 | |
| 2006 | /** |
Dianne Hackborn | 482566e | 2010-09-03 12:51:28 -0700 | [diff] [blame] | 2007 | * Constant for {@link #flags}: this is an app that is unable to |
| 2008 | * correctly save its state when going to the background, |
| 2009 | * so it can not be killed while in the background. |
| 2010 | * @hide |
Dianne Hackborn | baf42c6 | 2010-06-24 11:23:39 -0700 | [diff] [blame] | 2011 | */ |
Dianne Hackborn | 482566e | 2010-09-03 12:51:28 -0700 | [diff] [blame] | 2012 | public static final int FLAG_CANT_SAVE_STATE = 1<<0; |
Dianne Hackborn | baf42c6 | 2010-06-24 11:23:39 -0700 | [diff] [blame] | 2013 | |
| 2014 | /** |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 2015 | * Constant for {@link #flags}: this process is associated with a |
| 2016 | * persistent system app. |
| 2017 | * @hide |
| 2018 | */ |
| 2019 | public static final int FLAG_PERSISTENT = 1<<1; |
| 2020 | |
| 2021 | /** |
Dianne Hackborn | 0c38049 | 2012-08-20 17:23:30 -0700 | [diff] [blame] | 2022 | * Constant for {@link #flags}: this process is associated with a |
| 2023 | * persistent system app. |
| 2024 | * @hide |
| 2025 | */ |
| 2026 | public static final int FLAG_HAS_ACTIVITIES = 1<<2; |
| 2027 | |
| 2028 | /** |
Dianne Hackborn | baf42c6 | 2010-06-24 11:23:39 -0700 | [diff] [blame] | 2029 | * Flags of information. May be any of |
Dianne Hackborn | 482566e | 2010-09-03 12:51:28 -0700 | [diff] [blame] | 2030 | * {@link #FLAG_CANT_SAVE_STATE}. |
| 2031 | * @hide |
Dianne Hackborn | baf42c6 | 2010-06-24 11:23:39 -0700 | [diff] [blame] | 2032 | */ |
| 2033 | public int flags; |
Dianne Hackborn | 27ff913 | 2012-03-06 14:57:58 -0800 | [diff] [blame] | 2034 | |
| 2035 | /** |
| 2036 | * Last memory trim level reported to the process: corresponds to |
| 2037 | * the values supplied to {@link android.content.ComponentCallbacks2#onTrimMemory(int) |
| 2038 | * ComponentCallbacks2.onTrimMemory(int)}. |
| 2039 | */ |
| 2040 | public int lastTrimLevel; |
| 2041 | |
Dianne Hackborn | baf42c6 | 2010-06-24 11:23:39 -0700 | [diff] [blame] | 2042 | /** |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 2043 | * Constant for {@link #importance}: This process is running the |
| 2044 | * foreground UI; that is, it is the thing currently at the top of the screen |
| 2045 | * that the user is interacting with. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2046 | */ |
| 2047 | public static final int IMPORTANCE_FOREGROUND = 100; |
| 2048 | |
| 2049 | /** |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 2050 | * Constant for {@link #importance}: This process is running a foreground |
| 2051 | * service, for example to perform music playback even while the user is |
| 2052 | * not immediately in the app. This generally indicates that the process |
| 2053 | * is doing something the user actively cares about. |
| 2054 | */ |
| 2055 | public static final int IMPORTANCE_FOREGROUND_SERVICE = 125; |
| 2056 | |
| 2057 | /** |
| 2058 | * Constant for {@link #importance}: This process is running the foreground |
| 2059 | * UI, but the device is asleep so it is not visible to the user. This means |
| 2060 | * the user is not really aware of the process, because they can not see or |
| 2061 | * interact with it, but it is quite important because it what they expect to |
| 2062 | * return to once unlocking the device. |
| 2063 | */ |
| 2064 | public static final int IMPORTANCE_TOP_SLEEPING = 150; |
| 2065 | |
| 2066 | /** |
| 2067 | * Constant for {@link #importance}: This process is running something |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2068 | * that is actively visible to the user, though not in the immediate |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 2069 | * foreground. This may be running a window that is behind the current |
| 2070 | * foreground (so paused and with its state saved, not interacting with |
| 2071 | * the user, but visible to them to some degree); it may also be running |
| 2072 | * other services under the system's control that it inconsiders important. |
Dianne Hackborn | 860755f | 2010-06-03 18:47:52 -0700 | [diff] [blame] | 2073 | */ |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2074 | public static final int IMPORTANCE_VISIBLE = 200; |
Dianne Hackborn | 860755f | 2010-06-03 18:47:52 -0700 | [diff] [blame] | 2075 | |
| 2076 | /** |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 2077 | * Constant for {@link #importance}: This process is not something the user |
| 2078 | * is directly aware of, but is otherwise perceptable to them to some degree. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2079 | */ |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2080 | public static final int IMPORTANCE_PERCEPTIBLE = 130; |
| 2081 | |
| 2082 | /** |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 2083 | * Constant for {@link #importance}: This process is running an |
Dianne Hackborn | 5383f50 | 2010-10-22 12:59:20 -0700 | [diff] [blame] | 2084 | * application that can not save its state, and thus can't be killed |
| 2085 | * while in the background. |
| 2086 | * @hide |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2087 | */ |
Dianne Hackborn | 5383f50 | 2010-10-22 12:59:20 -0700 | [diff] [blame] | 2088 | public static final int IMPORTANCE_CANT_SAVE_STATE = 170; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2089 | |
| 2090 | /** |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 2091 | * Constant for {@link #importance}: This process is contains services |
| 2092 | * that should remain running. These are background services apps have |
| 2093 | * started, not something the user is aware of, so they may be killed by |
| 2094 | * the system relatively freely (though it is generally desired that they |
| 2095 | * stay running as long as they want to). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2096 | */ |
| 2097 | public static final int IMPORTANCE_SERVICE = 300; |
| 2098 | |
| 2099 | /** |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 2100 | * Constant for {@link #importance}: This process process contains |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2101 | * background code that is expendable. |
| 2102 | */ |
| 2103 | public static final int IMPORTANCE_BACKGROUND = 400; |
| 2104 | |
| 2105 | /** |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 2106 | * Constant for {@link #importance}: This process is empty of any |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2107 | * actively running code. |
| 2108 | */ |
| 2109 | public static final int IMPORTANCE_EMPTY = 500; |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 2110 | |
| 2111 | /** |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 2112 | * Constant for {@link #importance}: This process does not exist. |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 2113 | */ |
| 2114 | public static final int IMPORTANCE_GONE = 1000; |
| 2115 | |
| 2116 | /** @hide */ |
| 2117 | public static int procStateToImportance(int procState) { |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 2118 | if (procState == PROCESS_STATE_NONEXISTENT) { |
| 2119 | return IMPORTANCE_GONE; |
| 2120 | } else if (procState >= PROCESS_STATE_HOME) { |
| 2121 | return IMPORTANCE_BACKGROUND; |
| 2122 | } else if (procState >= PROCESS_STATE_SERVICE) { |
| 2123 | return IMPORTANCE_SERVICE; |
| 2124 | } else if (procState > PROCESS_STATE_HEAVY_WEIGHT) { |
| 2125 | return IMPORTANCE_CANT_SAVE_STATE; |
| 2126 | } else if (procState >= PROCESS_STATE_IMPORTANT_BACKGROUND) { |
| 2127 | return IMPORTANCE_PERCEPTIBLE; |
| 2128 | } else if (procState >= PROCESS_STATE_IMPORTANT_FOREGROUND) { |
| 2129 | return IMPORTANCE_VISIBLE; |
| 2130 | } else if (procState >= PROCESS_STATE_TOP_SLEEPING) { |
| 2131 | return IMPORTANCE_TOP_SLEEPING; |
| 2132 | } else if (procState >= PROCESS_STATE_FOREGROUND_SERVICE) { |
| 2133 | return IMPORTANCE_FOREGROUND_SERVICE; |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 2134 | } else { |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 2135 | return IMPORTANCE_FOREGROUND; |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 2136 | } |
| 2137 | } |
| 2138 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2139 | /** |
| 2140 | * The relative importance level that the system places on this |
| 2141 | * process. May be one of {@link #IMPORTANCE_FOREGROUND}, |
| 2142 | * {@link #IMPORTANCE_VISIBLE}, {@link #IMPORTANCE_SERVICE}, |
| 2143 | * {@link #IMPORTANCE_BACKGROUND}, or {@link #IMPORTANCE_EMPTY}. These |
| 2144 | * constants are numbered so that "more important" values are always |
| 2145 | * smaller than "less important" values. |
| 2146 | */ |
| 2147 | public int importance; |
| 2148 | |
| 2149 | /** |
| 2150 | * An additional ordering within a particular {@link #importance} |
| 2151 | * category, providing finer-grained information about the relative |
| 2152 | * utility of processes within a category. This number means nothing |
| 2153 | * except that a smaller values are more recently used (and thus |
| 2154 | * more important). Currently an LRU value is only maintained for |
| 2155 | * the {@link #IMPORTANCE_BACKGROUND} category, though others may |
| 2156 | * be maintained in the future. |
| 2157 | */ |
| 2158 | public int lru; |
Dianne Hackborn | 27ff913 | 2012-03-06 14:57:58 -0800 | [diff] [blame] | 2159 | |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 2160 | /** |
| 2161 | * Constant for {@link #importanceReasonCode}: nothing special has |
| 2162 | * been specified for the reason for this level. |
| 2163 | */ |
| 2164 | public static final int REASON_UNKNOWN = 0; |
| 2165 | |
| 2166 | /** |
| 2167 | * Constant for {@link #importanceReasonCode}: one of the application's |
| 2168 | * content providers is being used by another process. The pid of |
| 2169 | * the client process is in {@link #importanceReasonPid} and the |
| 2170 | * target provider in this process is in |
| 2171 | * {@link #importanceReasonComponent}. |
| 2172 | */ |
| 2173 | public static final int REASON_PROVIDER_IN_USE = 1; |
| 2174 | |
| 2175 | /** |
| 2176 | * Constant for {@link #importanceReasonCode}: one of the application's |
| 2177 | * content providers is being used by another process. The pid of |
| 2178 | * the client process is in {@link #importanceReasonPid} and the |
| 2179 | * target provider in this process is in |
| 2180 | * {@link #importanceReasonComponent}. |
| 2181 | */ |
| 2182 | public static final int REASON_SERVICE_IN_USE = 2; |
| 2183 | |
| 2184 | /** |
| 2185 | * The reason for {@link #importance}, if any. |
| 2186 | */ |
| 2187 | public int importanceReasonCode; |
| 2188 | |
| 2189 | /** |
| 2190 | * For the specified values of {@link #importanceReasonCode}, this |
| 2191 | * is the process ID of the other process that is a client of this |
| 2192 | * process. This will be 0 if no other process is using this one. |
| 2193 | */ |
| 2194 | public int importanceReasonPid; |
| 2195 | |
| 2196 | /** |
| 2197 | * For the specified values of {@link #importanceReasonCode}, this |
| 2198 | * is the name of the component that is being used in this process. |
| 2199 | */ |
| 2200 | public ComponentName importanceReasonComponent; |
| 2201 | |
Dianne Hackborn | 905577f | 2011-09-07 18:31:28 -0700 | [diff] [blame] | 2202 | /** |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 2203 | * When {@link #importanceReasonPid} is non-0, this is the importance |
Dianne Hackborn | 905577f | 2011-09-07 18:31:28 -0700 | [diff] [blame] | 2204 | * of the other pid. @hide |
| 2205 | */ |
| 2206 | public int importanceReasonImportance; |
| 2207 | |
Dianne Hackborn | 684bf34 | 2014-04-29 17:56:57 -0700 | [diff] [blame] | 2208 | /** |
| 2209 | * Current process state, as per PROCESS_STATE_* constants. |
| 2210 | * @hide |
| 2211 | */ |
| 2212 | public int processState; |
| 2213 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2214 | public RunningAppProcessInfo() { |
| 2215 | importance = IMPORTANCE_FOREGROUND; |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 2216 | importanceReasonCode = REASON_UNKNOWN; |
Dianne Hackborn | 684bf34 | 2014-04-29 17:56:57 -0700 | [diff] [blame] | 2217 | processState = PROCESS_STATE_IMPORTANT_FOREGROUND; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2218 | } |
| 2219 | |
| 2220 | public RunningAppProcessInfo(String pProcessName, int pPid, String pArr[]) { |
| 2221 | processName = pProcessName; |
| 2222 | pid = pPid; |
| 2223 | pkgList = pArr; |
| 2224 | } |
| 2225 | |
| 2226 | public int describeContents() { |
| 2227 | return 0; |
| 2228 | } |
| 2229 | |
| 2230 | public void writeToParcel(Parcel dest, int flags) { |
| 2231 | dest.writeString(processName); |
| 2232 | dest.writeInt(pid); |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 2233 | dest.writeInt(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2234 | dest.writeStringArray(pkgList); |
Dianne Hackborn | baf42c6 | 2010-06-24 11:23:39 -0700 | [diff] [blame] | 2235 | dest.writeInt(this.flags); |
Dianne Hackborn | 27ff913 | 2012-03-06 14:57:58 -0800 | [diff] [blame] | 2236 | dest.writeInt(lastTrimLevel); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2237 | dest.writeInt(importance); |
| 2238 | dest.writeInt(lru); |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 2239 | dest.writeInt(importanceReasonCode); |
| 2240 | dest.writeInt(importanceReasonPid); |
| 2241 | ComponentName.writeToParcel(importanceReasonComponent, dest); |
Dianne Hackborn | 905577f | 2011-09-07 18:31:28 -0700 | [diff] [blame] | 2242 | dest.writeInt(importanceReasonImportance); |
Dianne Hackborn | 684bf34 | 2014-04-29 17:56:57 -0700 | [diff] [blame] | 2243 | dest.writeInt(processState); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2244 | } |
| 2245 | |
| 2246 | public void readFromParcel(Parcel source) { |
| 2247 | processName = source.readString(); |
| 2248 | pid = source.readInt(); |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 2249 | uid = source.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2250 | pkgList = source.readStringArray(); |
Dianne Hackborn | baf42c6 | 2010-06-24 11:23:39 -0700 | [diff] [blame] | 2251 | flags = source.readInt(); |
Dianne Hackborn | 27ff913 | 2012-03-06 14:57:58 -0800 | [diff] [blame] | 2252 | lastTrimLevel = source.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2253 | importance = source.readInt(); |
| 2254 | lru = source.readInt(); |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 2255 | importanceReasonCode = source.readInt(); |
| 2256 | importanceReasonPid = source.readInt(); |
| 2257 | importanceReasonComponent = ComponentName.readFromParcel(source); |
Dianne Hackborn | 905577f | 2011-09-07 18:31:28 -0700 | [diff] [blame] | 2258 | importanceReasonImportance = source.readInt(); |
Dianne Hackborn | 684bf34 | 2014-04-29 17:56:57 -0700 | [diff] [blame] | 2259 | processState = source.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2260 | } |
| 2261 | |
| 2262 | public static final Creator<RunningAppProcessInfo> CREATOR = |
| 2263 | new Creator<RunningAppProcessInfo>() { |
| 2264 | public RunningAppProcessInfo createFromParcel(Parcel source) { |
| 2265 | return new RunningAppProcessInfo(source); |
| 2266 | } |
| 2267 | public RunningAppProcessInfo[] newArray(int size) { |
| 2268 | return new RunningAppProcessInfo[size]; |
| 2269 | } |
| 2270 | }; |
| 2271 | |
| 2272 | private RunningAppProcessInfo(Parcel source) { |
| 2273 | readFromParcel(source); |
| 2274 | } |
| 2275 | } |
| 2276 | |
| 2277 | /** |
Suchi Amalapurapu | f7f5dda | 2010-03-23 10:34:28 -0700 | [diff] [blame] | 2278 | * Returns a list of application processes installed on external media |
| 2279 | * that are running on the device. |
| 2280 | * |
Dianne Hackborn | c5bf758 | 2012-04-25 19:12:07 -0700 | [diff] [blame] | 2281 | * <p><b>Note: this method is only intended for debugging or building |
| 2282 | * a user-facing process management UI.</b></p> |
| 2283 | * |
Suchi Amalapurapu | f7f5dda | 2010-03-23 10:34:28 -0700 | [diff] [blame] | 2284 | * @return Returns a list of ApplicationInfo records, or null if none |
| 2285 | * This list ordering is not specified. |
| 2286 | * @hide |
| 2287 | */ |
| 2288 | public List<ApplicationInfo> getRunningExternalApplications() { |
| 2289 | try { |
| 2290 | return ActivityManagerNative.getDefault().getRunningExternalApplications(); |
| 2291 | } catch (RemoteException e) { |
| 2292 | return null; |
| 2293 | } |
| 2294 | } |
| 2295 | |
| 2296 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2297 | * Returns a list of application processes that are running on the device. |
Dianne Hackborn | c5bf758 | 2012-04-25 19:12:07 -0700 | [diff] [blame] | 2298 | * |
| 2299 | * <p><b>Note: this method is only intended for debugging or building |
| 2300 | * a user-facing process management UI.</b></p> |
| 2301 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2302 | * @return Returns a list of RunningAppProcessInfo records, or null if there are no |
| 2303 | * running processes (it will not return an empty list). This list ordering is not |
| 2304 | * specified. |
| 2305 | */ |
| 2306 | public List<RunningAppProcessInfo> getRunningAppProcesses() { |
| 2307 | try { |
| 2308 | return ActivityManagerNative.getDefault().getRunningAppProcesses(); |
| 2309 | } catch (RemoteException e) { |
| 2310 | return null; |
| 2311 | } |
| 2312 | } |
Dianne Hackborn | 27ff913 | 2012-03-06 14:57:58 -0800 | [diff] [blame] | 2313 | |
| 2314 | /** |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 2315 | * Return the importance of a given package name, based on the processes that are |
| 2316 | * currently running. The return value is one of the importance constants defined |
| 2317 | * in {@link RunningAppProcessInfo}, giving you the highest importance of all the |
| 2318 | * processes that this package has code running inside of. If there are no processes |
| 2319 | * running its code, {@link RunningAppProcessInfo#IMPORTANCE_GONE} is returned. |
| 2320 | */ |
| 2321 | public int getPackageImportance(String packageName) { |
| 2322 | try { |
| 2323 | int procState = ActivityManagerNative.getDefault().getPackageProcessState(packageName); |
| 2324 | return RunningAppProcessInfo.procStateToImportance(procState); |
| 2325 | } catch (RemoteException e) { |
| 2326 | return RunningAppProcessInfo.IMPORTANCE_GONE; |
| 2327 | } |
| 2328 | } |
| 2329 | |
| 2330 | /** |
Dianne Hackborn | 27ff913 | 2012-03-06 14:57:58 -0800 | [diff] [blame] | 2331 | * Return global memory state information for the calling process. This |
| 2332 | * does not fill in all fields of the {@link RunningAppProcessInfo}. The |
| 2333 | * only fields that will be filled in are |
| 2334 | * {@link RunningAppProcessInfo#pid}, |
| 2335 | * {@link RunningAppProcessInfo#uid}, |
| 2336 | * {@link RunningAppProcessInfo#lastTrimLevel}, |
| 2337 | * {@link RunningAppProcessInfo#importance}, |
| 2338 | * {@link RunningAppProcessInfo#lru}, and |
| 2339 | * {@link RunningAppProcessInfo#importanceReasonCode}. |
| 2340 | */ |
| 2341 | static public void getMyMemoryState(RunningAppProcessInfo outState) { |
| 2342 | try { |
| 2343 | ActivityManagerNative.getDefault().getMyMemoryState(outState); |
| 2344 | } catch (RemoteException e) { |
| 2345 | } |
| 2346 | } |
| 2347 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2348 | /** |
Dianne Hackborn | 4f21c4c | 2009-09-17 10:24:05 -0700 | [diff] [blame] | 2349 | * Return information about the memory usage of one or more processes. |
Dianne Hackborn | c5bf758 | 2012-04-25 19:12:07 -0700 | [diff] [blame] | 2350 | * |
| 2351 | * <p><b>Note: this method is only intended for debugging or building |
| 2352 | * a user-facing process management UI.</b></p> |
| 2353 | * |
Dianne Hackborn | 4f21c4c | 2009-09-17 10:24:05 -0700 | [diff] [blame] | 2354 | * @param pids The pids of the processes whose memory usage is to be |
| 2355 | * retrieved. |
| 2356 | * @return Returns an array of memory information, one for each |
| 2357 | * requested pid. |
| 2358 | */ |
| 2359 | public Debug.MemoryInfo[] getProcessMemoryInfo(int[] pids) { |
| 2360 | try { |
| 2361 | return ActivityManagerNative.getDefault().getProcessMemoryInfo(pids); |
| 2362 | } catch (RemoteException e) { |
| 2363 | return null; |
| 2364 | } |
| 2365 | } |
| 2366 | |
| 2367 | /** |
Dianne Hackborn | 03abb81 | 2010-01-04 18:43:19 -0800 | [diff] [blame] | 2368 | * @deprecated This is now just a wrapper for |
| 2369 | * {@link #killBackgroundProcesses(String)}; the previous behavior here |
| 2370 | * is no longer available to applications because it allows them to |
| 2371 | * break other applications by removing their alarms, stopping their |
| 2372 | * services, etc. |
| 2373 | */ |
| 2374 | @Deprecated |
| 2375 | public void restartPackage(String packageName) { |
| 2376 | killBackgroundProcesses(packageName); |
| 2377 | } |
| 2378 | |
| 2379 | /** |
| 2380 | * Have the system immediately kill all background processes associated |
| 2381 | * with the given package. This is the same as the kernel killing those |
| 2382 | * processes to reclaim memory; the system will take care of restarting |
| 2383 | * these processes in the future as needed. |
| 2384 | * |
| 2385 | * <p>You must hold the permission |
| 2386 | * {@link android.Manifest.permission#KILL_BACKGROUND_PROCESSES} to be able to |
| 2387 | * call this method. |
| 2388 | * |
| 2389 | * @param packageName The name of the package whose processes are to |
| 2390 | * be killed. |
| 2391 | */ |
| 2392 | public void killBackgroundProcesses(String packageName) { |
| 2393 | try { |
Dianne Hackborn | 1676c85 | 2012-09-10 14:52:30 -0700 | [diff] [blame] | 2394 | ActivityManagerNative.getDefault().killBackgroundProcesses(packageName, |
| 2395 | UserHandle.myUserId()); |
Dianne Hackborn | 03abb81 | 2010-01-04 18:43:19 -0800 | [diff] [blame] | 2396 | } catch (RemoteException e) { |
| 2397 | } |
| 2398 | } |
| 2399 | |
| 2400 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2401 | * Have the system perform a force stop of everything associated with |
| 2402 | * the given application package. All processes that share its uid |
| 2403 | * will be killed, all services it has running stopped, all activities |
| 2404 | * removed, etc. In addition, a {@link Intent#ACTION_PACKAGE_RESTARTED} |
| 2405 | * broadcast will be sent, so that any of its registered alarms can |
| 2406 | * be stopped, notifications removed, etc. |
| 2407 | * |
| 2408 | * <p>You must hold the permission |
Dianne Hackborn | 03abb81 | 2010-01-04 18:43:19 -0800 | [diff] [blame] | 2409 | * {@link android.Manifest.permission#FORCE_STOP_PACKAGES} to be able to |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2410 | * call this method. |
| 2411 | * |
| 2412 | * @param packageName The name of the package to be stopped. |
Zoltan Szatmary-Ban | 0bec95d | 2014-09-23 17:27:17 +0100 | [diff] [blame] | 2413 | * @param userId The user for which the running package is to be stopped. |
Dianne Hackborn | 03abb81 | 2010-01-04 18:43:19 -0800 | [diff] [blame] | 2414 | * |
| 2415 | * @hide This is not available to third party applications due to |
| 2416 | * it allowing them to break other applications by stopping their |
| 2417 | * services, removing their alarms, etc. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2418 | */ |
Zoltan Szatmary-Ban | 0bec95d | 2014-09-23 17:27:17 +0100 | [diff] [blame] | 2419 | public void forceStopPackageAsUser(String packageName, int userId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2420 | try { |
Zoltan Szatmary-Ban | 0bec95d | 2014-09-23 17:27:17 +0100 | [diff] [blame] | 2421 | ActivityManagerNative.getDefault().forceStopPackage(packageName, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2422 | } catch (RemoteException e) { |
| 2423 | } |
| 2424 | } |
Zoltan Szatmary-Ban | 0bec95d | 2014-09-23 17:27:17 +0100 | [diff] [blame] | 2425 | |
| 2426 | /** |
| 2427 | * @see #forceStopPackageAsUser(String, int) |
| 2428 | * @hide |
| 2429 | */ |
| 2430 | public void forceStopPackage(String packageName) { |
| 2431 | forceStopPackageAsUser(packageName, UserHandle.myUserId()); |
| 2432 | } |
| 2433 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2434 | /** |
| 2435 | * Get the device configuration attributes. |
| 2436 | */ |
| 2437 | public ConfigurationInfo getDeviceConfigurationInfo() { |
| 2438 | try { |
| 2439 | return ActivityManagerNative.getDefault().getDeviceConfigurationInfo(); |
| 2440 | } catch (RemoteException e) { |
| 2441 | } |
| 2442 | return null; |
| 2443 | } |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 2444 | |
| 2445 | /** |
| 2446 | * Get the preferred density of icons for the launcher. This is used when |
| 2447 | * custom drawables are created (e.g., for shortcuts). |
| 2448 | * |
| 2449 | * @return density in terms of DPI |
| 2450 | */ |
| 2451 | public int getLauncherLargeIconDensity() { |
| 2452 | final Resources res = mContext.getResources(); |
| 2453 | final int density = res.getDisplayMetrics().densityDpi; |
Dianne Hackborn | d96e3df | 2012-01-25 15:12:23 -0800 | [diff] [blame] | 2454 | final int sw = res.getConfiguration().smallestScreenWidthDp; |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 2455 | |
Dianne Hackborn | d96e3df | 2012-01-25 15:12:23 -0800 | [diff] [blame] | 2456 | if (sw < 600) { |
| 2457 | // Smaller than approx 7" tablets, use the regular icon size. |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 2458 | return density; |
| 2459 | } |
| 2460 | |
| 2461 | switch (density) { |
| 2462 | case DisplayMetrics.DENSITY_LOW: |
| 2463 | return DisplayMetrics.DENSITY_MEDIUM; |
| 2464 | case DisplayMetrics.DENSITY_MEDIUM: |
| 2465 | return DisplayMetrics.DENSITY_HIGH; |
Dianne Hackborn | d0356a1 | 2012-04-26 19:03:12 -0700 | [diff] [blame] | 2466 | case DisplayMetrics.DENSITY_TV: |
| 2467 | return DisplayMetrics.DENSITY_XHIGH; |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 2468 | case DisplayMetrics.DENSITY_HIGH: |
| 2469 | return DisplayMetrics.DENSITY_XHIGH; |
| 2470 | case DisplayMetrics.DENSITY_XHIGH: |
Dianne Hackborn | d96e3df | 2012-01-25 15:12:23 -0800 | [diff] [blame] | 2471 | return DisplayMetrics.DENSITY_XXHIGH; |
| 2472 | case DisplayMetrics.DENSITY_XXHIGH: |
| 2473 | return DisplayMetrics.DENSITY_XHIGH * 2; |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 2474 | default: |
Dianne Hackborn | d96e3df | 2012-01-25 15:12:23 -0800 | [diff] [blame] | 2475 | // The density is some abnormal value. Return some other |
| 2476 | // abnormal value that is a reasonable scaling of it. |
Dianne Hackborn | d0356a1 | 2012-04-26 19:03:12 -0700 | [diff] [blame] | 2477 | return (int)((density*1.5f)+.5f); |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 2478 | } |
| 2479 | } |
| 2480 | |
| 2481 | /** |
| 2482 | * Get the preferred launcher icon size. This is used when custom drawables |
| 2483 | * are created (e.g., for shortcuts). |
| 2484 | * |
| 2485 | * @return dimensions of square icons in terms of pixels |
| 2486 | */ |
| 2487 | public int getLauncherLargeIconSize() { |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 2488 | return getLauncherLargeIconSizeInner(mContext); |
| 2489 | } |
| 2490 | |
| 2491 | static int getLauncherLargeIconSizeInner(Context context) { |
| 2492 | final Resources res = context.getResources(); |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 2493 | final int size = res.getDimensionPixelSize(android.R.dimen.app_icon_size); |
Dianne Hackborn | d96e3df | 2012-01-25 15:12:23 -0800 | [diff] [blame] | 2494 | final int sw = res.getConfiguration().smallestScreenWidthDp; |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 2495 | |
Dianne Hackborn | d96e3df | 2012-01-25 15:12:23 -0800 | [diff] [blame] | 2496 | if (sw < 600) { |
| 2497 | // Smaller than approx 7" tablets, use the regular icon size. |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 2498 | return size; |
| 2499 | } |
| 2500 | |
| 2501 | final int density = res.getDisplayMetrics().densityDpi; |
| 2502 | |
| 2503 | switch (density) { |
| 2504 | case DisplayMetrics.DENSITY_LOW: |
| 2505 | return (size * DisplayMetrics.DENSITY_MEDIUM) / DisplayMetrics.DENSITY_LOW; |
| 2506 | case DisplayMetrics.DENSITY_MEDIUM: |
| 2507 | return (size * DisplayMetrics.DENSITY_HIGH) / DisplayMetrics.DENSITY_MEDIUM; |
Dianne Hackborn | d0356a1 | 2012-04-26 19:03:12 -0700 | [diff] [blame] | 2508 | case DisplayMetrics.DENSITY_TV: |
| 2509 | return (size * DisplayMetrics.DENSITY_XHIGH) / DisplayMetrics.DENSITY_HIGH; |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 2510 | case DisplayMetrics.DENSITY_HIGH: |
| 2511 | return (size * DisplayMetrics.DENSITY_XHIGH) / DisplayMetrics.DENSITY_HIGH; |
| 2512 | case DisplayMetrics.DENSITY_XHIGH: |
Dianne Hackborn | d96e3df | 2012-01-25 15:12:23 -0800 | [diff] [blame] | 2513 | return (size * DisplayMetrics.DENSITY_XXHIGH) / DisplayMetrics.DENSITY_XHIGH; |
| 2514 | case DisplayMetrics.DENSITY_XXHIGH: |
| 2515 | return (size * DisplayMetrics.DENSITY_XHIGH*2) / DisplayMetrics.DENSITY_XXHIGH; |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 2516 | default: |
Dianne Hackborn | d96e3df | 2012-01-25 15:12:23 -0800 | [diff] [blame] | 2517 | // The density is some abnormal value. Return some other |
| 2518 | // abnormal value that is a reasonable scaling of it. |
Dianne Hackborn | d0356a1 | 2012-04-26 19:03:12 -0700 | [diff] [blame] | 2519 | return (int)((size*1.5f) + .5f); |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 2520 | } |
| 2521 | } |
| 2522 | |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 2523 | /** |
| 2524 | * Returns "true" if the user interface is currently being messed with |
| 2525 | * by a monkey. |
| 2526 | */ |
| 2527 | public static boolean isUserAMonkey() { |
| 2528 | try { |
| 2529 | return ActivityManagerNative.getDefault().isUserAMonkey(); |
| 2530 | } catch (RemoteException e) { |
| 2531 | } |
| 2532 | return false; |
| 2533 | } |
Brett Chabot | 3b4fcbc | 2011-01-09 13:41:02 -0800 | [diff] [blame] | 2534 | |
| 2535 | /** |
| 2536 | * Returns "true" if device is running in a test harness. |
| 2537 | */ |
| 2538 | public static boolean isRunningInTestHarness() { |
| 2539 | return SystemProperties.getBoolean("ro.test_harness", false); |
| 2540 | } |
Peter Visontay | 8d224ca | 2011-02-18 16:39:19 +0000 | [diff] [blame] | 2541 | |
| 2542 | /** |
| 2543 | * Returns the launch count of each installed package. |
| 2544 | * |
| 2545 | * @hide |
| 2546 | */ |
Adam Lesinski | 0debc9a | 2014-07-16 19:09:13 -0700 | [diff] [blame] | 2547 | /*public Map<String, Integer> getAllPackageLaunchCounts() { |
Peter Visontay | 8d224ca | 2011-02-18 16:39:19 +0000 | [diff] [blame] | 2548 | try { |
| 2549 | IUsageStats usageStatsService = IUsageStats.Stub.asInterface( |
| 2550 | ServiceManager.getService("usagestats")); |
| 2551 | if (usageStatsService == null) { |
| 2552 | return new HashMap<String, Integer>(); |
| 2553 | } |
| 2554 | |
Dianne Hackborn | e22b3b1 | 2014-05-07 18:06:44 -0700 | [diff] [blame] | 2555 | UsageStats.PackageStats[] allPkgUsageStats = usageStatsService.getAllPkgUsageStats( |
| 2556 | ActivityThread.currentPackageName()); |
Peter Visontay | bfcda39 | 2011-03-02 18:53:37 +0000 | [diff] [blame] | 2557 | if (allPkgUsageStats == null) { |
| 2558 | return new HashMap<String, Integer>(); |
| 2559 | } |
| 2560 | |
Peter Visontay | 8d224ca | 2011-02-18 16:39:19 +0000 | [diff] [blame] | 2561 | Map<String, Integer> launchCounts = new HashMap<String, Integer>(); |
Dianne Hackborn | e22b3b1 | 2014-05-07 18:06:44 -0700 | [diff] [blame] | 2562 | for (UsageStats.PackageStats pkgUsageStats : allPkgUsageStats) { |
| 2563 | launchCounts.put(pkgUsageStats.getPackageName(), pkgUsageStats.getLaunchCount()); |
Peter Visontay | 8d224ca | 2011-02-18 16:39:19 +0000 | [diff] [blame] | 2564 | } |
| 2565 | |
| 2566 | return launchCounts; |
| 2567 | } catch (RemoteException e) { |
| 2568 | Log.w(TAG, "Could not query launch counts", e); |
| 2569 | return new HashMap<String, Integer>(); |
| 2570 | } |
Adam Lesinski | 0debc9a | 2014-07-16 19:09:13 -0700 | [diff] [blame] | 2571 | }*/ |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 2572 | |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 2573 | /** @hide */ |
| 2574 | public static int checkComponentPermission(String permission, int uid, |
| 2575 | int owningUid, boolean exported) { |
| 2576 | // Root, system server get to do everything. |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 2577 | final int appId = UserHandle.getAppId(uid); |
| 2578 | if (appId == Process.ROOT_UID || appId == Process.SYSTEM_UID) { |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 2579 | return PackageManager.PERMISSION_GRANTED; |
| 2580 | } |
| 2581 | // Isolated processes don't get any permissions. |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 2582 | if (UserHandle.isIsolated(uid)) { |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 2583 | return PackageManager.PERMISSION_DENIED; |
| 2584 | } |
| 2585 | // If there is a uid that owns whatever is being accessed, it has |
| 2586 | // blanket access to it regardless of the permissions it requires. |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 2587 | if (owningUid >= 0 && UserHandle.isSameApp(uid, owningUid)) { |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 2588 | return PackageManager.PERMISSION_GRANTED; |
| 2589 | } |
| 2590 | // If the target is not exported, then nobody else can get to it. |
| 2591 | if (!exported) { |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 2592 | /* |
| 2593 | RuntimeException here = new RuntimeException("here"); |
| 2594 | here.fillInStackTrace(); |
| 2595 | Slog.w(TAG, "Permission denied: checkComponentPermission() owningUid=" + owningUid, |
| 2596 | here); |
| 2597 | */ |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 2598 | return PackageManager.PERMISSION_DENIED; |
| 2599 | } |
| 2600 | if (permission == null) { |
| 2601 | return PackageManager.PERMISSION_GRANTED; |
| 2602 | } |
| 2603 | try { |
| 2604 | return AppGlobals.getPackageManager() |
| 2605 | .checkUidPermission(permission, uid); |
| 2606 | } catch (RemoteException e) { |
| 2607 | // Should never happen, but if it does... deny! |
| 2608 | Slog.e(TAG, "PackageManager is dead?!?", e); |
| 2609 | } |
| 2610 | return PackageManager.PERMISSION_DENIED; |
| 2611 | } |
| 2612 | |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 2613 | /** @hide */ |
| 2614 | public static int checkUidPermission(String permission, int uid) { |
| 2615 | try { |
| 2616 | return AppGlobals.getPackageManager() |
| 2617 | .checkUidPermission(permission, uid); |
| 2618 | } catch (RemoteException e) { |
| 2619 | // Should never happen, but if it does... deny! |
| 2620 | Slog.e(TAG, "PackageManager is dead?!?", e); |
| 2621 | } |
| 2622 | return PackageManager.PERMISSION_DENIED; |
| 2623 | } |
| 2624 | |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 2625 | /** |
| 2626 | * @hide |
| 2627 | * Helper for dealing with incoming user arguments to system service calls. |
| 2628 | * Takes care of checking permissions and converting USER_CURRENT to the |
| 2629 | * actual current user. |
| 2630 | * |
| 2631 | * @param callingPid The pid of the incoming call, as per Binder.getCallingPid(). |
| 2632 | * @param callingUid The uid of the incoming call, as per Binder.getCallingUid(). |
| 2633 | * @param userId The user id argument supplied by the caller -- this is the user |
| 2634 | * they want to run as. |
| 2635 | * @param allowAll If true, we will allow USER_ALL. This means you must be prepared |
| 2636 | * to get a USER_ALL returned and deal with it correctly. If false, |
| 2637 | * an exception will be thrown if USER_ALL is supplied. |
| 2638 | * @param requireFull If true, the caller must hold |
| 2639 | * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} to be able to run as a |
| 2640 | * different user than their current process; otherwise they must hold |
| 2641 | * {@link android.Manifest.permission#INTERACT_ACROSS_USERS}. |
| 2642 | * @param name Optional textual name of the incoming call; only for generating error messages. |
| 2643 | * @param callerPackage Optional package name of caller; only for error messages. |
| 2644 | * |
| 2645 | * @return Returns the user ID that the call should run as. Will always be a concrete |
| 2646 | * user number, unless <var>allowAll</var> is true in which case it could also be |
| 2647 | * USER_ALL. |
| 2648 | */ |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 2649 | public static int handleIncomingUser(int callingPid, int callingUid, int userId, |
| 2650 | boolean allowAll, boolean requireFull, String name, String callerPackage) { |
| 2651 | if (UserHandle.getUserId(callingUid) == userId) { |
| 2652 | return userId; |
| 2653 | } |
| 2654 | try { |
| 2655 | return ActivityManagerNative.getDefault().handleIncomingUser(callingPid, |
| 2656 | callingUid, userId, allowAll, requireFull, name, callerPackage); |
| 2657 | } catch (RemoteException e) { |
| 2658 | throw new SecurityException("Failed calling activity manager", e); |
| 2659 | } |
| 2660 | } |
| 2661 | |
Amith Yamasani | 0e8d7d6 | 2014-09-03 13:17:28 -0700 | [diff] [blame] | 2662 | /** |
| 2663 | * Gets the userId of the current foreground user. Requires system permissions. |
| 2664 | * @hide |
| 2665 | */ |
| 2666 | @SystemApi |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 2667 | public static int getCurrentUser() { |
| 2668 | UserInfo ui; |
| 2669 | try { |
| 2670 | ui = ActivityManagerNative.getDefault().getCurrentUser(); |
| 2671 | return ui != null ? ui.id : 0; |
| 2672 | } catch (RemoteException e) { |
| 2673 | return 0; |
| 2674 | } |
| 2675 | } |
| 2676 | |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 2677 | /** |
| 2678 | * @param userid the user's id. Zero indicates the default user |
| 2679 | * @hide |
| 2680 | */ |
| 2681 | public boolean switchUser(int userid) { |
| 2682 | try { |
| 2683 | return ActivityManagerNative.getDefault().switchUser(userid); |
| 2684 | } catch (RemoteException e) { |
| 2685 | return false; |
| 2686 | } |
| 2687 | } |
Dianne Hackborn | 5e03e2c | 2012-09-06 14:21:19 -0700 | [diff] [blame] | 2688 | |
| 2689 | /** |
| 2690 | * Return whether the given user is actively running. This means that |
| 2691 | * the user is in the "started" state, not "stopped" -- it is currently |
| 2692 | * allowed to run code through scheduled alarms, receiving broadcasts, |
| 2693 | * etc. A started user may be either the current foreground user or a |
| 2694 | * background user; the result here does not distinguish between the two. |
| 2695 | * @param userid the user's id. Zero indicates the default user. |
| 2696 | * @hide |
| 2697 | */ |
| 2698 | public boolean isUserRunning(int userid) { |
| 2699 | try { |
Dianne Hackborn | a8a9bd6 | 2012-10-09 15:36:59 -0700 | [diff] [blame] | 2700 | return ActivityManagerNative.getDefault().isUserRunning(userid, false); |
Dianne Hackborn | 5e03e2c | 2012-09-06 14:21:19 -0700 | [diff] [blame] | 2701 | } catch (RemoteException e) { |
| 2702 | return false; |
| 2703 | } |
| 2704 | } |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 2705 | |
| 2706 | /** |
| 2707 | * Perform a system dump of various state associated with the given application |
| 2708 | * package name. This call blocks while the dump is being performed, so should |
| 2709 | * not be done on a UI thread. The data will be written to the given file |
| 2710 | * descriptor as text. An application must hold the |
| 2711 | * {@link android.Manifest.permission#DUMP} permission to make this call. |
Dianne Hackborn | ebc15ef | 2013-10-09 17:36:57 -0700 | [diff] [blame] | 2712 | * @param fd The file descriptor that the dump should be written to. The file |
| 2713 | * descriptor is <em>not</em> closed by this function; the caller continues to |
| 2714 | * own it. |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 2715 | * @param packageName The name of the package that is to be dumped. |
| 2716 | */ |
| 2717 | public void dumpPackageState(FileDescriptor fd, String packageName) { |
| 2718 | dumpPackageStateStatic(fd, packageName); |
| 2719 | } |
| 2720 | |
| 2721 | /** |
| 2722 | * @hide |
| 2723 | */ |
| 2724 | public static void dumpPackageStateStatic(FileDescriptor fd, String packageName) { |
| 2725 | FileOutputStream fout = new FileOutputStream(fd); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 2726 | PrintWriter pw = new FastPrintWriter(fout); |
Dianne Hackborn | ab4a81b | 2014-10-09 17:59:38 -0700 | [diff] [blame] | 2727 | dumpService(pw, fd, "package", new String[] { packageName }); |
| 2728 | pw.println(); |
Dianne Hackborn | daa0d5c | 2013-11-06 16:30:29 -0800 | [diff] [blame] | 2729 | dumpService(pw, fd, Context.ACTIVITY_SERVICE, new String[] { |
| 2730 | "-a", "package", packageName }); |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 2731 | pw.println(); |
Dianne Hackborn | ab4a81b | 2014-10-09 17:59:38 -0700 | [diff] [blame] | 2732 | dumpService(pw, fd, "meminfo", new String[] { "--local", "--package", packageName }); |
Dianne Hackborn | daa0d5c | 2013-11-06 16:30:29 -0800 | [diff] [blame] | 2733 | pw.println(); |
Dianne Hackborn | ab4a81b | 2014-10-09 17:59:38 -0700 | [diff] [blame] | 2734 | dumpService(pw, fd, ProcessStats.SERVICE_NAME, new String[] { packageName }); |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 2735 | pw.println(); |
Dianne Hackborn | 904a857 | 2013-06-28 18:12:31 -0700 | [diff] [blame] | 2736 | dumpService(pw, fd, "usagestats", new String[] { "--packages", packageName }); |
| 2737 | pw.println(); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 2738 | dumpService(pw, fd, BatteryStats.SERVICE_NAME, new String[] { packageName }); |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 2739 | pw.flush(); |
| 2740 | } |
| 2741 | |
| 2742 | private static void dumpService(PrintWriter pw, FileDescriptor fd, String name, String[] args) { |
| 2743 | pw.print("DUMP OF SERVICE "); pw.print(name); pw.println(":"); |
| 2744 | IBinder service = ServiceManager.checkService(name); |
| 2745 | if (service == null) { |
| 2746 | pw.println(" (Service not found)"); |
| 2747 | return; |
| 2748 | } |
| 2749 | TransferPipe tp = null; |
| 2750 | try { |
| 2751 | pw.flush(); |
| 2752 | tp = new TransferPipe(); |
| 2753 | tp.setBufferPrefix(" "); |
Dianne Hackborn | daa0d5c | 2013-11-06 16:30:29 -0800 | [diff] [blame] | 2754 | service.dumpAsync(tp.getWriteFd().getFileDescriptor(), args); |
Dianne Hackborn | ab4a81b | 2014-10-09 17:59:38 -0700 | [diff] [blame] | 2755 | tp.go(fd, 10000); |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 2756 | } catch (Throwable e) { |
| 2757 | if (tp != null) { |
| 2758 | tp.kill(); |
| 2759 | } |
| 2760 | pw.println("Failure dumping service:"); |
| 2761 | e.printStackTrace(pw); |
| 2762 | } |
| 2763 | } |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 2764 | |
| 2765 | /** |
Dianne Hackborn | d59a5d5 | 2015-04-04 14:52:14 -0700 | [diff] [blame] | 2766 | * Request that the system start watching for the calling process to exceed a pss |
| 2767 | * size as given here. Once called, the system will look for any occassions where it |
| 2768 | * sees the associated process with a larger pss size and, when this happens, automatically |
| 2769 | * pull a heap dump from it and allow the user to share the data. Note that this request |
| 2770 | * continues running even if the process is killed and restarted. To remove the watch, |
| 2771 | * use {@link #clearWatchHeapLimit()}. |
| 2772 | * |
| 2773 | * <p>This API only work if running on a debuggable (userdebug or eng) build.</p> |
| 2774 | * |
| 2775 | * <p>Callers can optionally implement {@link #ACTION_REPORT_HEAP_LIMIT} to directly |
| 2776 | * handle heap limit reports themselves.</p> |
| 2777 | * |
| 2778 | * @param pssSize The size in bytes to set the limit at. |
| 2779 | */ |
| 2780 | public void setWatchHeapLimit(long pssSize) { |
| 2781 | try { |
| 2782 | ActivityManagerNative.getDefault().setDumpHeapDebugLimit(null, 0, pssSize, |
| 2783 | mContext.getPackageName()); |
| 2784 | } catch (RemoteException e) { |
| 2785 | } |
| 2786 | } |
| 2787 | |
| 2788 | /** |
| 2789 | * Action an app can implement to handle reports from {@link #setWatchHeapLimit(long)}. |
| 2790 | * If your package has an activity handling this action, it will be launched with the |
| 2791 | * heap data provided to it the same way as {@link Intent#ACTION_SEND}. Note that to |
| 2792 | * match the activty must support this action and a MIME type of "*/*". |
| 2793 | */ |
| 2794 | public static final String ACTION_REPORT_HEAP_LIMIT = "android.app.action.REPORT_HEAP_LIMIT"; |
| 2795 | |
| 2796 | /** |
| 2797 | * Clear a heap watch limit previously set by {@link #setWatchHeapLimit(long)}. |
| 2798 | */ |
| 2799 | public void clearWatchHeapLimit() { |
| 2800 | try { |
| 2801 | ActivityManagerNative.getDefault().setDumpHeapDebugLimit(null, 0, 0, null); |
| 2802 | } catch (RemoteException e) { |
| 2803 | } |
| 2804 | } |
| 2805 | |
| 2806 | /** |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 2807 | * @hide |
| 2808 | */ |
| 2809 | public void startLockTaskMode(int taskId) { |
| 2810 | try { |
| 2811 | ActivityManagerNative.getDefault().startLockTaskMode(taskId); |
| 2812 | } catch (RemoteException e) { |
| 2813 | } |
| 2814 | } |
| 2815 | |
| 2816 | /** |
| 2817 | * @hide |
| 2818 | */ |
| 2819 | public void stopLockTaskMode() { |
| 2820 | try { |
| 2821 | ActivityManagerNative.getDefault().stopLockTaskMode(); |
| 2822 | } catch (RemoteException e) { |
| 2823 | } |
| 2824 | } |
| 2825 | |
| 2826 | /** |
Jason Monk | 386c94f | 2014-07-14 16:42:24 -0400 | [diff] [blame] | 2827 | * Return whether currently in lock task mode. When in this mode |
| 2828 | * no new tasks can be created or switched to. |
| 2829 | * |
| 2830 | * @see Activity#startLockTask() |
Benjamin Franz | 4326114 | 2015-02-11 15:59:44 +0000 | [diff] [blame] | 2831 | * |
| 2832 | * @deprecated Use {@link #getLockTaskModeState} instead. |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 2833 | */ |
| 2834 | public boolean isInLockTaskMode() { |
Benjamin Franz | 4326114 | 2015-02-11 15:59:44 +0000 | [diff] [blame] | 2835 | return getLockTaskModeState() != LOCK_TASK_MODE_NONE; |
| 2836 | } |
| 2837 | |
| 2838 | /** |
| 2839 | * Return the current state of task locking. The three possible outcomes |
| 2840 | * are {@link #LOCK_TASK_MODE_NONE}, {@link #LOCK_TASK_MODE_LOCKED} |
| 2841 | * and {@link #LOCK_TASK_MODE_PINNED}. |
| 2842 | * |
| 2843 | * @see Activity#startLockTask() |
| 2844 | */ |
| 2845 | public int getLockTaskModeState() { |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 2846 | try { |
Benjamin Franz | 4326114 | 2015-02-11 15:59:44 +0000 | [diff] [blame] | 2847 | return ActivityManagerNative.getDefault().getLockTaskModeState(); |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 2848 | } catch (RemoteException e) { |
Benjamin Franz | 4326114 | 2015-02-11 15:59:44 +0000 | [diff] [blame] | 2849 | return ActivityManager.LOCK_TASK_MODE_NONE; |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 2850 | } |
| 2851 | } |
Winson Chung | 1147c40 | 2014-05-14 11:05:00 -0700 | [diff] [blame] | 2852 | |
| 2853 | /** |
| 2854 | * The AppTask allows you to manage your own application's tasks. |
| 2855 | * See {@link android.app.ActivityManager#getAppTasks()} |
| 2856 | */ |
| 2857 | public static class AppTask { |
| 2858 | private IAppTask mAppTaskImpl; |
| 2859 | |
| 2860 | /** @hide */ |
| 2861 | public AppTask(IAppTask task) { |
| 2862 | mAppTaskImpl = task; |
| 2863 | } |
| 2864 | |
| 2865 | /** |
| 2866 | * Finishes all activities in this task and removes it from the recent tasks list. |
| 2867 | */ |
| 2868 | public void finishAndRemoveTask() { |
| 2869 | try { |
| 2870 | mAppTaskImpl.finishAndRemoveTask(); |
| 2871 | } catch (RemoteException e) { |
| 2872 | Slog.e(TAG, "Invalid AppTask", e); |
| 2873 | } |
| 2874 | } |
| 2875 | |
| 2876 | /** |
| 2877 | * Get the RecentTaskInfo associated with this task. |
| 2878 | * |
| 2879 | * @return The RecentTaskInfo for this task, or null if the task no longer exists. |
| 2880 | */ |
| 2881 | public RecentTaskInfo getTaskInfo() { |
| 2882 | try { |
| 2883 | return mAppTaskImpl.getTaskInfo(); |
| 2884 | } catch (RemoteException e) { |
| 2885 | Slog.e(TAG, "Invalid AppTask", e); |
| 2886 | return null; |
| 2887 | } |
| 2888 | } |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 2889 | |
| 2890 | /** |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 2891 | * Bring this task to the foreground. If it contains activities, they will be |
| 2892 | * brought to the foreground with it and their instances re-created if needed. |
| 2893 | * If it doesn't contain activities, the root activity of the task will be |
| 2894 | * re-launched. |
| 2895 | */ |
| 2896 | public void moveToFront() { |
| 2897 | try { |
| 2898 | mAppTaskImpl.moveToFront(); |
| 2899 | } catch (RemoteException e) { |
| 2900 | Slog.e(TAG, "Invalid AppTask", e); |
| 2901 | } |
| 2902 | } |
| 2903 | |
| 2904 | /** |
| 2905 | * Start an activity in this task. Brings the task to the foreground. If this task |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 2906 | * is not currently active (that is, its id < 0), then a new activity for the given |
| 2907 | * Intent will be launched as the root of the task and the task brought to the |
| 2908 | * foreground. Otherwise, if this task is currently active and the Intent does not specify |
| 2909 | * an activity to launch in a new task, then a new activity for the given Intent will |
| 2910 | * be launched on top of the task and the task brought to the foreground. If this |
| 2911 | * task is currently active and the Intent specifies {@link Intent#FLAG_ACTIVITY_NEW_TASK} |
| 2912 | * or would otherwise be launched in to a new task, then the activity not launched but |
| 2913 | * this task be brought to the foreground and a new intent delivered to the top |
| 2914 | * activity if appropriate. |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 2915 | * |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 2916 | * <p>In other words, you generally want to use an Intent here that does not specify |
| 2917 | * {@link Intent#FLAG_ACTIVITY_NEW_TASK} or {@link Intent#FLAG_ACTIVITY_NEW_DOCUMENT}, |
| 2918 | * and let the system do the right thing.</p> |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 2919 | * |
| 2920 | * @param intent The Intent describing the new activity to be launched on the task. |
| 2921 | * @param options Optional launch options. |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 2922 | * |
| 2923 | * @see Activity#startActivity(android.content.Intent, android.os.Bundle) |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 2924 | */ |
| 2925 | public void startActivity(Context context, Intent intent, Bundle options) { |
| 2926 | ActivityThread thread = ActivityThread.currentActivityThread(); |
| 2927 | thread.getInstrumentation().execStartActivityFromAppTask(context, |
| 2928 | thread.getApplicationThread(), mAppTaskImpl, intent, options); |
| 2929 | } |
| 2930 | |
| 2931 | /** |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 2932 | * Modify the {@link Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} flag in the root |
| 2933 | * Intent of this AppTask. |
| 2934 | * |
| 2935 | * @param exclude If true, {@link Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} will |
| 2936 | * be set; otherwise, it will be cleared. |
| 2937 | */ |
| 2938 | public void setExcludeFromRecents(boolean exclude) { |
| 2939 | try { |
| 2940 | mAppTaskImpl.setExcludeFromRecents(exclude); |
| 2941 | } catch (RemoteException e) { |
| 2942 | Slog.e(TAG, "Invalid AppTask", e); |
| 2943 | } |
| 2944 | } |
Winson Chung | 1147c40 | 2014-05-14 11:05:00 -0700 | [diff] [blame] | 2945 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2946 | } |