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