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