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