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