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