The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.app; |
| 18 | |
Dianne Hackborn | b4e1249 | 2013-06-26 15:08:19 -0700 | [diff] [blame] | 19 | import android.R; |
Dianne Hackborn | 91268cf | 2013-06-13 19:06:50 -0700 | [diff] [blame] | 20 | import android.os.BatteryStats; |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 21 | import android.os.IBinder; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 22 | import com.android.internal.app.IUsageStats; |
| 23 | import com.android.internal.os.PkgUsageStats; |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 24 | import com.android.internal.os.TransferPipe; |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 25 | import com.android.internal.util.FastPrintWriter; |
Dianne Hackborn | b375632 | 2011-08-12 13:58:13 -0700 | [diff] [blame] | 26 | import com.android.internal.util.MemInfoReader; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 27 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | import android.content.ComponentName; |
| 29 | import android.content.Context; |
| 30 | import android.content.Intent; |
Suchi Amalapurapu | f7f5dda | 2010-03-23 10:34:28 -0700 | [diff] [blame] | 31 | import android.content.pm.ApplicationInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | import android.content.pm.ConfigurationInfo; |
| 33 | import android.content.pm.IPackageDataObserver; |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 34 | import android.content.pm.PackageManager; |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 35 | import android.content.pm.UserInfo; |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 36 | import android.content.res.Resources; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | import android.graphics.Bitmap; |
Dianne Hackborn | b375632 | 2011-08-12 13:58:13 -0700 | [diff] [blame] | 38 | import android.graphics.Point; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 39 | import android.graphics.Rect; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 40 | import android.hardware.display.DisplayManagerGlobal; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 41 | import android.os.Bundle; |
Dianne Hackborn | 4f21c4c | 2009-09-17 10:24:05 -0700 | [diff] [blame] | 42 | import android.os.Debug; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | import android.os.Handler; |
| 44 | import android.os.Parcel; |
| 45 | import android.os.Parcelable; |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 46 | import android.os.Process; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 47 | import android.os.RemoteException; |
Peter Visontay | 8d224ca | 2011-02-18 16:39:19 +0000 | [diff] [blame] | 48 | import android.os.ServiceManager; |
Dianne Hackborn | 2c6c5e6 | 2009-10-08 17:55:49 -0700 | [diff] [blame] | 49 | import android.os.SystemProperties; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 50 | import android.os.UserHandle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | import android.text.TextUtils; |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 52 | import android.util.DisplayMetrics; |
Peter Visontay | 8d224ca | 2011-02-18 16:39:19 +0000 | [diff] [blame] | 53 | import android.util.Log; |
Dianne Hackborn | b375632 | 2011-08-12 13:58:13 -0700 | [diff] [blame] | 54 | import android.util.Slog; |
| 55 | import android.view.Display; |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 56 | |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 57 | import java.io.FileDescriptor; |
| 58 | import java.io.FileOutputStream; |
| 59 | import java.io.PrintWriter; |
Peter Visontay | 8d224ca | 2011-02-18 16:39:19 +0000 | [diff] [blame] | 60 | import java.util.HashMap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | import java.util.List; |
Peter Visontay | 8d224ca | 2011-02-18 16:39:19 +0000 | [diff] [blame] | 62 | import java.util.Map; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | |
| 64 | /** |
| 65 | * Interact with the overall activities running in the system. |
| 66 | */ |
| 67 | public class ActivityManager { |
| 68 | private static String TAG = "ActivityManager"; |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 69 | private static boolean localLOGV = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | |
| 71 | private final Context mContext; |
| 72 | private final Handler mHandler; |
| 73 | |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 74 | /** |
| 75 | * Result for IActivityManager.startActivity: an error where the |
| 76 | * start had to be canceled. |
| 77 | * @hide |
| 78 | */ |
| 79 | public static final int START_CANCELED = -6; |
| 80 | |
| 81 | /** |
| 82 | * Result for IActivityManager.startActivity: an error where the |
| 83 | * thing being started is not an activity. |
| 84 | * @hide |
| 85 | */ |
| 86 | public static final int START_NOT_ACTIVITY = -5; |
| 87 | |
| 88 | /** |
| 89 | * Result for IActivityManager.startActivity: an error where the |
| 90 | * caller does not have permission to start the activity. |
| 91 | * @hide |
| 92 | */ |
| 93 | public static final int START_PERMISSION_DENIED = -4; |
| 94 | |
| 95 | /** |
| 96 | * Result for IActivityManager.startActivity: an error where the |
| 97 | * caller has requested both to forward a result and to receive |
| 98 | * a result. |
| 99 | * @hide |
| 100 | */ |
| 101 | public static final int START_FORWARD_AND_REQUEST_CONFLICT = -3; |
| 102 | |
| 103 | /** |
| 104 | * Result for IActivityManager.startActivity: an error where the |
| 105 | * requested class is not found. |
| 106 | * @hide |
| 107 | */ |
| 108 | public static final int START_CLASS_NOT_FOUND = -2; |
| 109 | |
| 110 | /** |
| 111 | * Result for IActivityManager.startActivity: an error where the |
| 112 | * given Intent could not be resolved to an activity. |
| 113 | * @hide |
| 114 | */ |
| 115 | public static final int START_INTENT_NOT_RESOLVED = -1; |
| 116 | |
| 117 | /** |
| 118 | * Result for IActivityManaqer.startActivity: the activity was started |
| 119 | * successfully as normal. |
| 120 | * @hide |
| 121 | */ |
| 122 | public static final int START_SUCCESS = 0; |
| 123 | |
| 124 | /** |
| 125 | * Result for IActivityManaqer.startActivity: the caller asked that the Intent not |
| 126 | * be executed if it is the recipient, and that is indeed the case. |
| 127 | * @hide |
| 128 | */ |
| 129 | public static final int START_RETURN_INTENT_TO_CALLER = 1; |
| 130 | |
| 131 | /** |
| 132 | * Result for IActivityManaqer.startActivity: activity wasn't really started, but |
| 133 | * a task was simply brought to the foreground. |
| 134 | * @hide |
| 135 | */ |
| 136 | public static final int START_TASK_TO_FRONT = 2; |
| 137 | |
| 138 | /** |
| 139 | * Result for IActivityManaqer.startActivity: activity wasn't really started, but |
| 140 | * the given Intent was given to the existing top activity. |
| 141 | * @hide |
| 142 | */ |
| 143 | public static final int START_DELIVERED_TO_TOP = 3; |
| 144 | |
| 145 | /** |
| 146 | * Result for IActivityManaqer.startActivity: request was canceled because |
| 147 | * app switches are temporarily canceled to ensure the user's last request |
| 148 | * (such as pressing home) is performed. |
| 149 | * @hide |
| 150 | */ |
| 151 | public static final int START_SWITCHES_CANCELED = 4; |
| 152 | |
| 153 | /** |
| 154 | * Flag for IActivityManaqer.startActivity: do special start mode where |
| 155 | * a new activity is launched only if it is needed. |
| 156 | * @hide |
| 157 | */ |
| 158 | public static final int START_FLAG_ONLY_IF_NEEDED = 1<<0; |
| 159 | |
| 160 | /** |
| 161 | * Flag for IActivityManaqer.startActivity: launch the app for |
| 162 | * debugging. |
| 163 | * @hide |
| 164 | */ |
| 165 | public static final int START_FLAG_DEBUG = 1<<1; |
| 166 | |
| 167 | /** |
| 168 | * Flag for IActivityManaqer.startActivity: launch the app for |
| 169 | * OpenGL tracing. |
| 170 | * @hide |
| 171 | */ |
| 172 | public static final int START_FLAG_OPENGL_TRACES = 1<<2; |
| 173 | |
| 174 | /** |
| 175 | * Flag for IActivityManaqer.startActivity: if the app is being |
| 176 | * launched for profiling, automatically stop the profiler once done. |
| 177 | * @hide |
| 178 | */ |
| 179 | public static final int START_FLAG_AUTO_STOP_PROFILER = 1<<3; |
| 180 | |
| 181 | /** |
| 182 | * Result for IActivityManaqer.broadcastIntent: success! |
| 183 | * @hide |
| 184 | */ |
| 185 | public static final int BROADCAST_SUCCESS = 0; |
| 186 | |
| 187 | /** |
| 188 | * Result for IActivityManaqer.broadcastIntent: attempt to broadcast |
| 189 | * a sticky intent without appropriate permission. |
| 190 | * @hide |
| 191 | */ |
| 192 | public static final int BROADCAST_STICKY_CANT_HAVE_PERMISSION = -1; |
| 193 | |
| 194 | /** |
| 195 | * Type for IActivityManaqer.getIntentSender: this PendingIntent is |
| 196 | * for a sendBroadcast operation. |
| 197 | * @hide |
| 198 | */ |
| 199 | public static final int INTENT_SENDER_BROADCAST = 1; |
| 200 | |
| 201 | /** |
| 202 | * Type for IActivityManaqer.getIntentSender: this PendingIntent is |
| 203 | * for a startActivity operation. |
| 204 | * @hide |
| 205 | */ |
| 206 | public static final int INTENT_SENDER_ACTIVITY = 2; |
| 207 | |
| 208 | /** |
| 209 | * Type for IActivityManaqer.getIntentSender: this PendingIntent is |
| 210 | * for an activity result operation. |
| 211 | * @hide |
| 212 | */ |
| 213 | public static final int INTENT_SENDER_ACTIVITY_RESULT = 3; |
| 214 | |
| 215 | /** |
| 216 | * Type for IActivityManaqer.getIntentSender: this PendingIntent is |
| 217 | * for a startService operation. |
| 218 | * @hide |
| 219 | */ |
| 220 | public static final int INTENT_SENDER_SERVICE = 4; |
| 221 | |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 222 | /** @hide User operation call: success! */ |
| 223 | public static final int USER_OP_SUCCESS = 0; |
| 224 | |
| 225 | /** @hide User operation call: given user id is not known. */ |
| 226 | public static final int USER_OP_UNKNOWN_USER = -1; |
| 227 | |
| 228 | /** @hide User operation call: given user id is the current user, can't be stopped. */ |
| 229 | public static final int USER_OP_IS_CURRENT = -2; |
| 230 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 231 | /** @hide Process is a persistent system process. */ |
| 232 | public static final int PROCESS_STATE_PERSISTENT = 0; |
| 233 | |
| 234 | /** @hide Process is a persistent system process and is doing UI. */ |
| 235 | public static final int PROCESS_STATE_PERSISTENT_UI = 1; |
| 236 | |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 237 | /** @hide Process is hosting the current top activities. Note that this covers |
| 238 | * all activities that are visible to the user. */ |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 239 | public static final int PROCESS_STATE_TOP = 2; |
| 240 | |
| 241 | /** @hide Process is important to the user, and something they are aware of. */ |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 242 | public static final int PROCESS_STATE_IMPORTANT_FOREGROUND = 3; |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 243 | |
| 244 | /** @hide Process is important to the user, but not something they are aware of. */ |
| 245 | public static final int PROCESS_STATE_IMPORTANT_BACKGROUND = 4; |
| 246 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 247 | /** @hide Process is in the background running a backup/restore operation. */ |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 248 | public static final int PROCESS_STATE_BACKUP = 5; |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 249 | |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 250 | /** @hide Process is in the background, but it can't restore its state so we want |
| 251 | * to try to avoid killing it. */ |
| 252 | public static final int PROCESS_STATE_HEAVY_WEIGHT = 6; |
| 253 | |
| 254 | /** @hide Process is in the background running a service. Unlike oom_adj, this level |
| 255 | * is used for both the normal running in background state and the executing |
| 256 | * operations state. */ |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 257 | public static final int PROCESS_STATE_SERVICE = 7; |
| 258 | |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 259 | /** @hide Process is in the background running a receiver. Note that from the |
| 260 | * perspective of oom_adj receivers run at a higher foreground level, but for our |
| 261 | * prioritization here that is not necessary and putting them below services means |
| 262 | * many fewer changes in some process states as they receive broadcasts. */ |
| 263 | public static final int PROCESS_STATE_RECEIVER = 8; |
| 264 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 265 | /** @hide Process is in the background but hosts the home activity. */ |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 266 | public static final int PROCESS_STATE_HOME = 9; |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 267 | |
| 268 | /** @hide Process is in the background but hosts the last shown activity. */ |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 269 | public static final int PROCESS_STATE_LAST_ACTIVITY = 10; |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 270 | |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 271 | /** @hide Process is being cached for later use and contains activities. */ |
| 272 | public static final int PROCESS_STATE_CACHED_ACTIVITY = 11; |
| 273 | |
| 274 | /** @hide Process is being cached for later use and is a client of another cached |
| 275 | * process that contains activities. */ |
| 276 | public static final int PROCESS_STATE_CACHED_ACTIVITY_CLIENT = 12; |
| 277 | |
| 278 | /** @hide Process is being cached for later use and is empty. */ |
| 279 | public static final int PROCESS_STATE_CACHED_EMPTY = 13; |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 280 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 281 | /*package*/ ActivityManager(Context context, Handler handler) { |
| 282 | mContext = context; |
| 283 | mHandler = handler; |
| 284 | } |
| 285 | |
| 286 | /** |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 287 | * Screen compatibility mode: the application most always run in |
| 288 | * compatibility mode. |
| 289 | * @hide |
| 290 | */ |
| 291 | public static final int COMPAT_MODE_ALWAYS = -1; |
| 292 | |
| 293 | /** |
| 294 | * Screen compatibility mode: the application can never run in |
| 295 | * compatibility mode. |
| 296 | * @hide |
| 297 | */ |
| 298 | public static final int COMPAT_MODE_NEVER = -2; |
| 299 | |
| 300 | /** |
| 301 | * Screen compatibility mode: unknown. |
| 302 | * @hide |
| 303 | */ |
| 304 | public static final int COMPAT_MODE_UNKNOWN = -3; |
| 305 | |
| 306 | /** |
| 307 | * Screen compatibility mode: the application currently has compatibility |
| 308 | * mode disabled. |
| 309 | * @hide |
| 310 | */ |
| 311 | public static final int COMPAT_MODE_DISABLED = 0; |
| 312 | |
| 313 | /** |
| 314 | * Screen compatibility mode: the application currently has compatibility |
| 315 | * mode enabled. |
| 316 | * @hide |
| 317 | */ |
| 318 | public static final int COMPAT_MODE_ENABLED = 1; |
| 319 | |
| 320 | /** |
| 321 | * Screen compatibility mode: request to toggle the application's |
| 322 | * compatibility mode. |
| 323 | * @hide |
| 324 | */ |
| 325 | public static final int COMPAT_MODE_TOGGLE = 2; |
| 326 | |
| 327 | /** @hide */ |
| 328 | public int getFrontActivityScreenCompatMode() { |
| 329 | try { |
| 330 | return ActivityManagerNative.getDefault().getFrontActivityScreenCompatMode(); |
| 331 | } catch (RemoteException e) { |
| 332 | // System dead, we will be dead too soon! |
| 333 | return 0; |
| 334 | } |
| 335 | } |
| 336 | |
Dianne Hackborn | df9799f | 2011-05-12 15:16:33 -0700 | [diff] [blame] | 337 | /** @hide */ |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 338 | public void setFrontActivityScreenCompatMode(int mode) { |
| 339 | try { |
| 340 | ActivityManagerNative.getDefault().setFrontActivityScreenCompatMode(mode); |
| 341 | } catch (RemoteException e) { |
| 342 | // System dead, we will be dead too soon! |
| 343 | } |
| 344 | } |
| 345 | |
Dianne Hackborn | df9799f | 2011-05-12 15:16:33 -0700 | [diff] [blame] | 346 | /** @hide */ |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 347 | public int getPackageScreenCompatMode(String packageName) { |
| 348 | try { |
| 349 | return ActivityManagerNative.getDefault().getPackageScreenCompatMode(packageName); |
| 350 | } catch (RemoteException e) { |
| 351 | // System dead, we will be dead too soon! |
| 352 | return 0; |
| 353 | } |
| 354 | } |
| 355 | |
Dianne Hackborn | df9799f | 2011-05-12 15:16:33 -0700 | [diff] [blame] | 356 | /** @hide */ |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 357 | public void setPackageScreenCompatMode(String packageName, int mode) { |
| 358 | try { |
| 359 | ActivityManagerNative.getDefault().setPackageScreenCompatMode(packageName, mode); |
| 360 | } catch (RemoteException e) { |
| 361 | // System dead, we will be dead too soon! |
| 362 | } |
| 363 | } |
| 364 | |
Dianne Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 365 | /** @hide */ |
| 366 | public boolean getPackageAskScreenCompat(String packageName) { |
| 367 | try { |
| 368 | return ActivityManagerNative.getDefault().getPackageAskScreenCompat(packageName); |
| 369 | } catch (RemoteException e) { |
| 370 | // System dead, we will be dead too soon! |
| 371 | return false; |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | /** @hide */ |
| 376 | public void setPackageAskScreenCompat(String packageName, boolean ask) { |
| 377 | try { |
| 378 | ActivityManagerNative.getDefault().setPackageAskScreenCompat(packageName, ask); |
| 379 | } catch (RemoteException e) { |
| 380 | // System dead, we will be dead too soon! |
| 381 | } |
| 382 | } |
| 383 | |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 384 | /** |
Dianne Hackborn | 2c6c5e6 | 2009-10-08 17:55:49 -0700 | [diff] [blame] | 385 | * Return the approximate per-application memory class of the current |
| 386 | * device. This gives you an idea of how hard a memory limit you should |
| 387 | * impose on your application to let the overall system work best. The |
| 388 | * returned value is in megabytes; the baseline Android memory class is |
| 389 | * 16 (which happens to be the Java heap limit of those devices); some |
| 390 | * device with more memory may return 24 or even higher numbers. |
| 391 | */ |
| 392 | public int getMemoryClass() { |
| 393 | return staticGetMemoryClass(); |
| 394 | } |
| 395 | |
| 396 | /** @hide */ |
| 397 | static public int staticGetMemoryClass() { |
| 398 | // Really brain dead right now -- just take this from the configured |
| 399 | // 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] | 400 | String vmHeapSize = SystemProperties.get("dalvik.vm.heapgrowthlimit", ""); |
Dianne Hackborn | de39851 | 2011-01-18 18:45:21 -0800 | [diff] [blame] | 401 | if (vmHeapSize != null && !"".equals(vmHeapSize)) { |
| 402 | return Integer.parseInt(vmHeapSize.substring(0, vmHeapSize.length()-1)); |
| 403 | } |
| 404 | return staticGetLargeMemoryClass(); |
Dianne Hackborn | 4e24aac | 2010-12-23 11:43:46 -0800 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | /** |
| 408 | * Return the approximate per-application memory class of the current |
| 409 | * device when an application is running with a large heap. This is the |
| 410 | * space available for memory-intensive applications; most applications |
| 411 | * should not need this amount of memory, and should instead stay with the |
| 412 | * {@link #getMemoryClass()} limit. The returned value is in megabytes. |
| 413 | * This may be the same size as {@link #getMemoryClass()} on memory |
| 414 | * constrained devices, or it may be significantly larger on devices with |
| 415 | * a large amount of available RAM. |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 416 | * |
| 417 | * <p>The is the size of the application's Dalvik heap if it has |
| 418 | * specified <code>android:largeHeap="true"</code> in its manifest. |
Dianne Hackborn | 4e24aac | 2010-12-23 11:43:46 -0800 | [diff] [blame] | 419 | */ |
| 420 | public int getLargeMemoryClass() { |
| 421 | return staticGetLargeMemoryClass(); |
| 422 | } |
| 423 | |
| 424 | /** @hide */ |
| 425 | static public int staticGetLargeMemoryClass() { |
| 426 | // Really brain dead right now -- just take this from the configured |
| 427 | // 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] | 428 | String vmHeapSize = SystemProperties.get("dalvik.vm.heapsize", "16m"); |
| 429 | return Integer.parseInt(vmHeapSize.substring(0, vmHeapSize.length()-1)); |
| 430 | } |
Dianne Hackborn | b4e1249 | 2013-06-26 15:08:19 -0700 | [diff] [blame] | 431 | |
| 432 | /** |
| 433 | * Returns true if this is a low-RAM device. Exactly whether a device is low-RAM |
| 434 | * is ultimately up to the device configuration, but currently it generally means |
| 435 | * something in the class of a 512MB device with about a 800x480 or less screen. |
| 436 | * This is mostly intended to be used by apps to determine whether they should turn |
| 437 | * off certain features that require more RAM. |
| 438 | */ |
| 439 | public boolean isLowRamDevice() { |
| 440 | return isLowRamDeviceStatic(); |
| 441 | } |
| 442 | |
| 443 | /** @hide */ |
| 444 | public static boolean isLowRamDeviceStatic() { |
| 445 | return Resources.getSystem().getBoolean(com.android.internal.R.bool.config_lowRamDevice); |
| 446 | } |
| 447 | |
Dianne Hackborn | 2c6c5e6 | 2009-10-08 17:55:49 -0700 | [diff] [blame] | 448 | /** |
Dianne Hackborn | b375632 | 2011-08-12 13:58:13 -0700 | [diff] [blame] | 449 | * Used by persistent processes to determine if they are running on a |
| 450 | * higher-end device so should be okay using hardware drawing acceleration |
| 451 | * (which tends to consume a lot more RAM). |
| 452 | * @hide |
| 453 | */ |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 454 | static public boolean isHighEndGfx() { |
Dianne Hackborn | b4e1249 | 2013-06-26 15:08:19 -0700 | [diff] [blame] | 455 | return !isLowRamDeviceStatic() && |
| 456 | !Resources.getSystem().getBoolean(com.android.internal.R.bool.config_avoidGfxAccel); |
Dianne Hackborn | 49d228b3 | 2011-08-24 17:37:31 -0700 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 460 | * Information you can retrieve about tasks that the user has most recently |
| 461 | * started or visited. |
| 462 | */ |
| 463 | public static class RecentTaskInfo implements Parcelable { |
| 464 | /** |
| 465 | * If this task is currently running, this is the identifier for it. |
| 466 | * If it is not running, this will be -1. |
| 467 | */ |
| 468 | public int id; |
| 469 | |
| 470 | /** |
Dianne Hackborn | d94df45 | 2011-02-16 18:53:31 -0800 | [diff] [blame] | 471 | * The true identifier of this task, valid even if it is not running. |
| 472 | */ |
| 473 | public int persistentId; |
| 474 | |
| 475 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 476 | * The original Intent used to launch the task. You can use this |
| 477 | * Intent to re-launch the task (if it is no longer running) or bring |
| 478 | * the current task to the front. |
| 479 | */ |
| 480 | public Intent baseIntent; |
| 481 | |
| 482 | /** |
| 483 | * If this task was started from an alias, this is the actual |
| 484 | * activity component that was initially started; the component of |
| 485 | * the baseIntent in this case is the name of the actual activity |
| 486 | * implementation that the alias referred to. Otherwise, this is null. |
| 487 | */ |
| 488 | public ComponentName origActivity; |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 489 | |
| 490 | /** |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 491 | * Description of the task's last state. |
| 492 | */ |
| 493 | public CharSequence description; |
Craig Mautner | 6d90fed | 2013-05-22 15:03:10 -0700 | [diff] [blame] | 494 | |
| 495 | /** |
| 496 | * The id of the ActivityStack this Task was on most recently. |
| 497 | */ |
| 498 | public int stackId; |
| 499 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 500 | public RecentTaskInfo() { |
| 501 | } |
| 502 | |
Craig Mautner | 6d90fed | 2013-05-22 15:03:10 -0700 | [diff] [blame] | 503 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 504 | public int describeContents() { |
| 505 | return 0; |
| 506 | } |
| 507 | |
Craig Mautner | 6d90fed | 2013-05-22 15:03:10 -0700 | [diff] [blame] | 508 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 509 | public void writeToParcel(Parcel dest, int flags) { |
| 510 | dest.writeInt(id); |
Dianne Hackborn | d94df45 | 2011-02-16 18:53:31 -0800 | [diff] [blame] | 511 | dest.writeInt(persistentId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 512 | if (baseIntent != null) { |
| 513 | dest.writeInt(1); |
| 514 | baseIntent.writeToParcel(dest, 0); |
| 515 | } else { |
| 516 | dest.writeInt(0); |
| 517 | } |
| 518 | ComponentName.writeToParcel(origActivity, dest); |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 519 | TextUtils.writeToParcel(description, dest, |
| 520 | Parcelable.PARCELABLE_WRITE_RETURN_VALUE); |
Craig Mautner | 6d90fed | 2013-05-22 15:03:10 -0700 | [diff] [blame] | 521 | dest.writeInt(stackId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | public void readFromParcel(Parcel source) { |
| 525 | id = source.readInt(); |
Dianne Hackborn | d94df45 | 2011-02-16 18:53:31 -0800 | [diff] [blame] | 526 | persistentId = source.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 527 | if (source.readInt() != 0) { |
| 528 | baseIntent = Intent.CREATOR.createFromParcel(source); |
| 529 | } else { |
| 530 | baseIntent = null; |
| 531 | } |
| 532 | origActivity = ComponentName.readFromParcel(source); |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 533 | description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); |
Craig Mautner | 6d90fed | 2013-05-22 15:03:10 -0700 | [diff] [blame] | 534 | stackId = source.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 535 | } |
Craig Mautner | 6d90fed | 2013-05-22 15:03:10 -0700 | [diff] [blame] | 536 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 537 | public static final Creator<RecentTaskInfo> CREATOR |
| 538 | = new Creator<RecentTaskInfo>() { |
| 539 | public RecentTaskInfo createFromParcel(Parcel source) { |
| 540 | return new RecentTaskInfo(source); |
| 541 | } |
| 542 | public RecentTaskInfo[] newArray(int size) { |
| 543 | return new RecentTaskInfo[size]; |
| 544 | } |
| 545 | }; |
| 546 | |
| 547 | private RecentTaskInfo(Parcel source) { |
| 548 | readFromParcel(source); |
| 549 | } |
| 550 | } |
| 551 | |
| 552 | /** |
| 553 | * Flag for use with {@link #getRecentTasks}: return all tasks, even those |
| 554 | * that have set their |
| 555 | * {@link android.content.Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} flag. |
| 556 | */ |
| 557 | public static final int RECENT_WITH_EXCLUDED = 0x0001; |
| 558 | |
| 559 | /** |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 560 | * Provides a list that does not contain any |
Dianne Hackborn | 53d9264d | 2010-04-13 12:49:14 -0700 | [diff] [blame] | 561 | * recent tasks that currently are not available to the user. |
| 562 | */ |
| 563 | public static final int RECENT_IGNORE_UNAVAILABLE = 0x0002; |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 564 | |
| 565 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 566 | * Return a list of the tasks that the user has recently launched, with |
| 567 | * the most recent being first and older ones after in order. |
Dianne Hackborn | c5bf758 | 2012-04-25 19:12:07 -0700 | [diff] [blame] | 568 | * |
| 569 | * <p><b>Note: this method is only intended for debugging and presenting |
| 570 | * task management user interfaces</b>. This should never be used for |
| 571 | * core logic in an application, such as deciding between different |
| 572 | * behaviors based on the information found here. Such uses are |
| 573 | * <em>not</em> supported, and will likely break in the future. For |
| 574 | * example, if multiple applications can be actively running at the |
| 575 | * same time, assumptions made about the meaning of the data here for |
| 576 | * purposes of control flow will be incorrect.</p> |
| 577 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 578 | * @param maxNum The maximum number of entries to return in the list. The |
| 579 | * actual number returned may be smaller, depending on how many tasks the |
| 580 | * user has started and the maximum number the system can remember. |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 581 | * @param flags Information about what to return. May be any combination |
Dianne Hackborn | 805fd7e | 2011-01-16 18:30:29 -0800 | [diff] [blame] | 582 | * of {@link #RECENT_WITH_EXCLUDED} and {@link #RECENT_IGNORE_UNAVAILABLE}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 583 | * |
| 584 | * @return Returns a list of RecentTaskInfo records describing each of |
| 585 | * the recent tasks. |
| 586 | * |
| 587 | * @throws SecurityException Throws SecurityException if the caller does |
| 588 | * not hold the {@link android.Manifest.permission#GET_TASKS} permission. |
| 589 | */ |
| 590 | public List<RecentTaskInfo> getRecentTasks(int maxNum, int flags) |
| 591 | throws SecurityException { |
| 592 | try { |
| 593 | return ActivityManagerNative.getDefault().getRecentTasks(maxNum, |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 594 | flags, UserHandle.myUserId()); |
Amith Yamasani | 8264408 | 2012-08-03 13:09:11 -0700 | [diff] [blame] | 595 | } catch (RemoteException e) { |
| 596 | // System dead, we will be dead too soon! |
| 597 | return null; |
| 598 | } |
| 599 | } |
| 600 | |
| 601 | /** |
| 602 | * Same as {@link #getRecentTasks(int, int)} but returns the recent tasks for a |
| 603 | * specific user. It requires holding |
| 604 | * the {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permission. |
| 605 | * @param maxNum The maximum number of entries to return in the list. The |
| 606 | * actual number returned may be smaller, depending on how many tasks the |
| 607 | * user has started and the maximum number the system can remember. |
| 608 | * @param flags Information about what to return. May be any combination |
| 609 | * of {@link #RECENT_WITH_EXCLUDED} and {@link #RECENT_IGNORE_UNAVAILABLE}. |
| 610 | * |
| 611 | * @return Returns a list of RecentTaskInfo records describing each of |
| 612 | * the recent tasks. |
| 613 | * |
| 614 | * @throws SecurityException Throws SecurityException if the caller does |
| 615 | * not hold the {@link android.Manifest.permission#GET_TASKS} or the |
| 616 | * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permissions. |
| 617 | * @hide |
| 618 | */ |
| 619 | public List<RecentTaskInfo> getRecentTasksForUser(int maxNum, int flags, int userId) |
| 620 | throws SecurityException { |
| 621 | try { |
| 622 | return ActivityManagerNative.getDefault().getRecentTasks(maxNum, |
| 623 | flags, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 624 | } catch (RemoteException e) { |
| 625 | // System dead, we will be dead too soon! |
| 626 | return null; |
| 627 | } |
| 628 | } |
| 629 | |
| 630 | /** |
| 631 | * Information you can retrieve about a particular task that is currently |
| 632 | * "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] | 633 | * 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] | 634 | * means that the user has gone to it and never closed it, but currently |
| 635 | * the system may have killed its process and is only holding on to its |
| 636 | * last state in order to restart it when the user returns. |
| 637 | */ |
| 638 | public static class RunningTaskInfo implements Parcelable { |
| 639 | /** |
| 640 | * A unique identifier for this task. |
| 641 | */ |
| 642 | public int id; |
| 643 | |
| 644 | /** |
| 645 | * The component launched as the first activity in the task. This can |
| 646 | * be considered the "application" of this task. |
| 647 | */ |
| 648 | public ComponentName baseActivity; |
| 649 | |
| 650 | /** |
| 651 | * The activity component at the top of the history stack of the task. |
| 652 | * This is what the user is currently doing. |
| 653 | */ |
| 654 | public ComponentName topActivity; |
| 655 | |
| 656 | /** |
Dianne Hackborn | 805fd7e | 2011-01-16 18:30:29 -0800 | [diff] [blame] | 657 | * Thumbnail representation of the task's current state. Currently |
| 658 | * always null. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 659 | */ |
| 660 | public Bitmap thumbnail; |
| 661 | |
| 662 | /** |
| 663 | * Description of the task's current state. |
| 664 | */ |
| 665 | public CharSequence description; |
| 666 | |
| 667 | /** |
| 668 | * Number of activities in this task. |
| 669 | */ |
| 670 | public int numActivities; |
| 671 | |
| 672 | /** |
| 673 | * Number of activities that are currently running (not stopped |
| 674 | * and persisted) in this task. |
| 675 | */ |
| 676 | public int numRunning; |
| 677 | |
| 678 | public RunningTaskInfo() { |
| 679 | } |
| 680 | |
| 681 | public int describeContents() { |
| 682 | return 0; |
| 683 | } |
| 684 | |
| 685 | public void writeToParcel(Parcel dest, int flags) { |
| 686 | dest.writeInt(id); |
| 687 | ComponentName.writeToParcel(baseActivity, dest); |
| 688 | ComponentName.writeToParcel(topActivity, dest); |
| 689 | if (thumbnail != null) { |
| 690 | dest.writeInt(1); |
| 691 | thumbnail.writeToParcel(dest, 0); |
| 692 | } else { |
| 693 | dest.writeInt(0); |
| 694 | } |
| 695 | TextUtils.writeToParcel(description, dest, |
| 696 | Parcelable.PARCELABLE_WRITE_RETURN_VALUE); |
| 697 | dest.writeInt(numActivities); |
| 698 | dest.writeInt(numRunning); |
| 699 | } |
| 700 | |
| 701 | public void readFromParcel(Parcel source) { |
| 702 | id = source.readInt(); |
| 703 | baseActivity = ComponentName.readFromParcel(source); |
| 704 | topActivity = ComponentName.readFromParcel(source); |
| 705 | if (source.readInt() != 0) { |
| 706 | thumbnail = Bitmap.CREATOR.createFromParcel(source); |
| 707 | } else { |
| 708 | thumbnail = null; |
| 709 | } |
| 710 | description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); |
| 711 | numActivities = source.readInt(); |
| 712 | numRunning = source.readInt(); |
| 713 | } |
| 714 | |
| 715 | public static final Creator<RunningTaskInfo> CREATOR = new Creator<RunningTaskInfo>() { |
| 716 | public RunningTaskInfo createFromParcel(Parcel source) { |
| 717 | return new RunningTaskInfo(source); |
| 718 | } |
| 719 | public RunningTaskInfo[] newArray(int size) { |
| 720 | return new RunningTaskInfo[size]; |
| 721 | } |
| 722 | }; |
| 723 | |
| 724 | private RunningTaskInfo(Parcel source) { |
| 725 | readFromParcel(source); |
| 726 | } |
| 727 | } |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 728 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 729 | /** |
| 730 | * Return a list of the tasks that are currently running, with |
| 731 | * the most recent being first and older ones after in order. Note that |
| 732 | * "running" does not mean any of the task's code is currently loaded or |
| 733 | * activity -- the task may have been frozen by the system, so that it |
| 734 | * can be restarted in its previous state when next brought to the |
| 735 | * foreground. |
| 736 | * |
| 737 | * @param maxNum The maximum number of entries to return in the list. The |
| 738 | * actual number returned may be smaller, depending on how many tasks the |
| 739 | * user has started. |
Jim Miller | 0b2a6d0 | 2010-07-13 18:01:29 -0700 | [diff] [blame] | 740 | * |
| 741 | * @param flags Optional flags |
| 742 | * @param receiver Optional receiver for delayed thumbnails |
| 743 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 744 | * @return Returns a list of RunningTaskInfo records describing each of |
| 745 | * the running tasks. |
| 746 | * |
Jim Miller | 0b2a6d0 | 2010-07-13 18:01:29 -0700 | [diff] [blame] | 747 | * Some thumbnails may not be available at the time of this call. The optional |
| 748 | * receiver may be used to receive those thumbnails. |
| 749 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 750 | * @throws SecurityException Throws SecurityException if the caller does |
| 751 | * not hold the {@link android.Manifest.permission#GET_TASKS} permission. |
Jim Miller | 0b2a6d0 | 2010-07-13 18:01:29 -0700 | [diff] [blame] | 752 | * |
| 753 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 754 | */ |
Jim Miller | 0b2a6d0 | 2010-07-13 18:01:29 -0700 | [diff] [blame] | 755 | public List<RunningTaskInfo> getRunningTasks(int maxNum, int flags, IThumbnailReceiver receiver) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 756 | throws SecurityException { |
| 757 | try { |
Jim Miller | 0b2a6d0 | 2010-07-13 18:01:29 -0700 | [diff] [blame] | 758 | return ActivityManagerNative.getDefault().getTasks(maxNum, flags, receiver); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 759 | } catch (RemoteException e) { |
| 760 | // System dead, we will be dead too soon! |
| 761 | return null; |
| 762 | } |
| 763 | } |
Jim Miller | 0b2a6d0 | 2010-07-13 18:01:29 -0700 | [diff] [blame] | 764 | |
| 765 | /** |
| 766 | * Return a list of the tasks that are currently running, with |
| 767 | * the most recent being first and older ones after in order. Note that |
| 768 | * "running" does not mean any of the task's code is currently loaded or |
| 769 | * activity -- the task may have been frozen by the system, so that it |
| 770 | * can be restarted in its previous state when next brought to the |
| 771 | * foreground. |
| 772 | * |
Dianne Hackborn | c5bf758 | 2012-04-25 19:12:07 -0700 | [diff] [blame] | 773 | * <p><b>Note: this method is only intended for debugging and presenting |
| 774 | * task management user interfaces</b>. This should never be used for |
| 775 | * core logic in an application, such as deciding between different |
| 776 | * behaviors based on the information found here. Such uses are |
| 777 | * <em>not</em> supported, and will likely break in the future. For |
| 778 | * example, if multiple applications can be actively running at the |
| 779 | * same time, assumptions made about the meaning of the data here for |
| 780 | * purposes of control flow will be incorrect.</p> |
| 781 | * |
Jim Miller | 0b2a6d0 | 2010-07-13 18:01:29 -0700 | [diff] [blame] | 782 | * @param maxNum The maximum number of entries to return in the list. The |
| 783 | * actual number returned may be smaller, depending on how many tasks the |
| 784 | * user has started. |
| 785 | * |
| 786 | * @return Returns a list of RunningTaskInfo records describing each of |
| 787 | * the running tasks. |
| 788 | * |
| 789 | * @throws SecurityException Throws SecurityException if the caller does |
| 790 | * not hold the {@link android.Manifest.permission#GET_TASKS} permission. |
| 791 | */ |
| 792 | public List<RunningTaskInfo> getRunningTasks(int maxNum) |
| 793 | throws SecurityException { |
| 794 | return getRunningTasks(maxNum, 0, null); |
| 795 | } |
| 796 | |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 797 | /** |
| 798 | * Remove some end of a task's activity stack that is not part of |
| 799 | * the main application. The selected activities will be finished, so |
| 800 | * they are no longer part of the main task. |
| 801 | * |
| 802 | * @param taskId The identifier of the task. |
| 803 | * @param subTaskIndex The number of the sub-task; this corresponds |
| 804 | * to the index of the thumbnail returned by {@link #getTaskThumbnails(int)}. |
| 805 | * @return Returns true if the sub-task was found and was removed. |
| 806 | * |
| 807 | * @hide |
| 808 | */ |
| 809 | public boolean removeSubTask(int taskId, int subTaskIndex) |
| 810 | throws SecurityException { |
| 811 | try { |
| 812 | return ActivityManagerNative.getDefault().removeSubTask(taskId, subTaskIndex); |
| 813 | } catch (RemoteException e) { |
| 814 | // System dead, we will be dead too soon! |
| 815 | return false; |
| 816 | } |
| 817 | } |
| 818 | |
| 819 | /** |
| 820 | * If set, the process of the root activity of the task will be killed |
| 821 | * as part of removing the task. |
| 822 | * @hide |
| 823 | */ |
| 824 | public static final int REMOVE_TASK_KILL_PROCESS = 0x0001; |
| 825 | |
| 826 | /** |
| 827 | * Completely remove the given task. |
| 828 | * |
| 829 | * @param taskId Identifier of the task to be removed. |
| 830 | * @param flags Additional operational flags. May be 0 or |
| 831 | * {@link #REMOVE_TASK_KILL_PROCESS}. |
| 832 | * @return Returns true if the given task was found and removed. |
| 833 | * |
| 834 | * @hide |
| 835 | */ |
| 836 | public boolean removeTask(int taskId, int flags) |
| 837 | throws SecurityException { |
| 838 | try { |
| 839 | return ActivityManagerNative.getDefault().removeTask(taskId, flags); |
| 840 | } catch (RemoteException e) { |
| 841 | // System dead, we will be dead too soon! |
| 842 | return false; |
| 843 | } |
| 844 | } |
| 845 | |
Dianne Hackborn | d94df45 | 2011-02-16 18:53:31 -0800 | [diff] [blame] | 846 | /** @hide */ |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 847 | public static class TaskThumbnails implements Parcelable { |
| 848 | public Bitmap mainThumbnail; |
| 849 | |
| 850 | public int numSubThumbbails; |
| 851 | |
| 852 | /** @hide */ |
| 853 | public IThumbnailRetriever retriever; |
| 854 | |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 855 | public TaskThumbnails() { |
| 856 | } |
| 857 | |
| 858 | public Bitmap getSubThumbnail(int index) { |
| 859 | try { |
| 860 | return retriever.getThumbnail(index); |
| 861 | } catch (RemoteException e) { |
| 862 | return null; |
| 863 | } |
| 864 | } |
| 865 | |
| 866 | public int describeContents() { |
| 867 | return 0; |
| 868 | } |
| 869 | |
| 870 | public void writeToParcel(Parcel dest, int flags) { |
| 871 | if (mainThumbnail != null) { |
| 872 | dest.writeInt(1); |
| 873 | mainThumbnail.writeToParcel(dest, 0); |
| 874 | } else { |
| 875 | dest.writeInt(0); |
| 876 | } |
| 877 | dest.writeInt(numSubThumbbails); |
| 878 | dest.writeStrongInterface(retriever); |
| 879 | } |
| 880 | |
| 881 | public void readFromParcel(Parcel source) { |
| 882 | if (source.readInt() != 0) { |
| 883 | mainThumbnail = Bitmap.CREATOR.createFromParcel(source); |
| 884 | } else { |
| 885 | mainThumbnail = null; |
| 886 | } |
| 887 | numSubThumbbails = source.readInt(); |
| 888 | retriever = IThumbnailRetriever.Stub.asInterface(source.readStrongBinder()); |
| 889 | } |
| 890 | |
| 891 | public static final Creator<TaskThumbnails> CREATOR = new Creator<TaskThumbnails>() { |
| 892 | public TaskThumbnails createFromParcel(Parcel source) { |
| 893 | return new TaskThumbnails(source); |
| 894 | } |
| 895 | public TaskThumbnails[] newArray(int size) { |
| 896 | return new TaskThumbnails[size]; |
| 897 | } |
| 898 | }; |
| 899 | |
| 900 | private TaskThumbnails(Parcel source) { |
| 901 | readFromParcel(source); |
| 902 | } |
| 903 | } |
| 904 | |
| 905 | /** @hide */ |
| 906 | public TaskThumbnails getTaskThumbnails(int id) throws SecurityException { |
Dianne Hackborn | d94df45 | 2011-02-16 18:53:31 -0800 | [diff] [blame] | 907 | try { |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 908 | return ActivityManagerNative.getDefault().getTaskThumbnails(id); |
Dianne Hackborn | d94df45 | 2011-02-16 18:53:31 -0800 | [diff] [blame] | 909 | } catch (RemoteException e) { |
| 910 | // System dead, we will be dead too soon! |
| 911 | return null; |
| 912 | } |
| 913 | } |
Dianne Hackborn | 15491c6 | 2012-09-19 10:59:14 -0700 | [diff] [blame] | 914 | |
| 915 | /** @hide */ |
| 916 | public Bitmap getTaskTopThumbnail(int id) throws SecurityException { |
| 917 | try { |
| 918 | return ActivityManagerNative.getDefault().getTaskTopThumbnail(id); |
| 919 | } catch (RemoteException e) { |
| 920 | // System dead, we will be dead too soon! |
| 921 | return null; |
| 922 | } |
| 923 | } |
| 924 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 925 | /** |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 926 | * Flag for {@link #moveTaskToFront(int, int)}: also move the "home" |
| 927 | * activity along with the task, so it is positioned immediately behind |
| 928 | * the task. |
| 929 | */ |
| 930 | public static final int MOVE_TASK_WITH_HOME = 0x00000001; |
| 931 | |
| 932 | /** |
Dianne Hackborn | d94df45 | 2011-02-16 18:53:31 -0800 | [diff] [blame] | 933 | * Flag for {@link #moveTaskToFront(int, int)}: don't count this as a |
| 934 | * user-instigated action, so the current activity will not receive a |
| 935 | * hint that the user is leaving. |
| 936 | */ |
| 937 | public static final int MOVE_TASK_NO_USER_ACTION = 0x00000002; |
| 938 | |
| 939 | /** |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 940 | * Equivalent to calling {@link #moveTaskToFront(int, int, Bundle)} |
| 941 | * with a null options argument. |
| 942 | * |
| 943 | * @param taskId The identifier of the task to be moved, as found in |
| 944 | * {@link RunningTaskInfo} or {@link RecentTaskInfo}. |
| 945 | * @param flags Additional operational flags, 0 or more of |
Craig Mautner | ecbfe25 | 2013-03-28 11:58:25 -0700 | [diff] [blame] | 946 | * {@link #MOVE_TASK_WITH_HOME}, {@link #MOVE_TASK_NO_USER_ACTION}. |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 947 | */ |
| 948 | public void moveTaskToFront(int taskId, int flags) { |
| 949 | moveTaskToFront(taskId, flags, null); |
| 950 | } |
| 951 | |
| 952 | /** |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 953 | * Ask that the task associated with a given task ID be moved to the |
| 954 | * front of the stack, so it is now visible to the user. Requires that |
| 955 | * the caller hold permission {@link android.Manifest.permission#REORDER_TASKS} |
| 956 | * or a SecurityException will be thrown. |
| 957 | * |
| 958 | * @param taskId The identifier of the task to be moved, as found in |
| 959 | * {@link RunningTaskInfo} or {@link RecentTaskInfo}. |
| 960 | * @param flags Additional operational flags, 0 or more of |
Craig Mautner | ecbfe25 | 2013-03-28 11:58:25 -0700 | [diff] [blame] | 961 | * {@link #MOVE_TASK_WITH_HOME}, {@link #MOVE_TASK_NO_USER_ACTION}. |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 962 | * @param options Additional options for the operation, either null or |
| 963 | * as per {@link Context#startActivity(Intent, android.os.Bundle) |
| 964 | * Context.startActivity(Intent, Bundle)}. |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 965 | */ |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 966 | public void moveTaskToFront(int taskId, int flags, Bundle options) { |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 967 | try { |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 968 | ActivityManagerNative.getDefault().moveTaskToFront(taskId, flags, options); |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 969 | } catch (RemoteException e) { |
| 970 | // System dead, we will be dead too soon! |
| 971 | } |
| 972 | } |
| 973 | |
| 974 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 975 | * Information you can retrieve about a particular Service that is |
| 976 | * currently running in the system. |
| 977 | */ |
| 978 | public static class RunningServiceInfo implements Parcelable { |
| 979 | /** |
| 980 | * The service component. |
| 981 | */ |
| 982 | public ComponentName service; |
| 983 | |
| 984 | /** |
| 985 | * If non-zero, this is the process the service is running in. |
| 986 | */ |
| 987 | public int pid; |
| 988 | |
| 989 | /** |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 990 | * The UID that owns this service. |
| 991 | */ |
| 992 | public int uid; |
| 993 | |
| 994 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 995 | * The name of the process this service runs in. |
| 996 | */ |
| 997 | public String process; |
| 998 | |
| 999 | /** |
| 1000 | * Set to true if the service has asked to run as a foreground process. |
| 1001 | */ |
| 1002 | public boolean foreground; |
| 1003 | |
| 1004 | /** |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 1005 | * The time when the service was first made active, either by someone |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1006 | * starting or binding to it. This |
| 1007 | * is in units of {@link android.os.SystemClock#elapsedRealtime()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1008 | */ |
| 1009 | public long activeSince; |
| 1010 | |
| 1011 | /** |
| 1012 | * Set to true if this service has been explicitly started. |
| 1013 | */ |
| 1014 | public boolean started; |
| 1015 | |
| 1016 | /** |
| 1017 | * Number of clients connected to the service. |
| 1018 | */ |
| 1019 | public int clientCount; |
| 1020 | |
| 1021 | /** |
| 1022 | * Number of times the service's process has crashed while the service |
| 1023 | * is running. |
| 1024 | */ |
| 1025 | public int crashCount; |
| 1026 | |
| 1027 | /** |
| 1028 | * The time when there was last activity in the service (either |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1029 | * explicit requests to start it or clients binding to it). This |
| 1030 | * is in units of {@link android.os.SystemClock#uptimeMillis()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1031 | */ |
| 1032 | public long lastActivityTime; |
| 1033 | |
| 1034 | /** |
| 1035 | * If non-zero, this service is not currently running, but scheduled to |
| 1036 | * restart at the given time. |
| 1037 | */ |
| 1038 | public long restarting; |
| 1039 | |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 1040 | /** |
| 1041 | * Bit for {@link #flags}: set if this service has been |
| 1042 | * explicitly started. |
| 1043 | */ |
| 1044 | public static final int FLAG_STARTED = 1<<0; |
| 1045 | |
| 1046 | /** |
| 1047 | * Bit for {@link #flags}: set if the service has asked to |
| 1048 | * run as a foreground process. |
| 1049 | */ |
| 1050 | public static final int FLAG_FOREGROUND = 1<<1; |
| 1051 | |
| 1052 | /** |
| 1053 | * Bit for {@link #flags): set if the service is running in a |
| 1054 | * core system process. |
| 1055 | */ |
| 1056 | public static final int FLAG_SYSTEM_PROCESS = 1<<2; |
| 1057 | |
| 1058 | /** |
| 1059 | * Bit for {@link #flags): set if the service is running in a |
| 1060 | * persistent process. |
| 1061 | */ |
| 1062 | public static final int FLAG_PERSISTENT_PROCESS = 1<<3; |
| 1063 | |
| 1064 | /** |
| 1065 | * Running flags. |
| 1066 | */ |
| 1067 | public int flags; |
| 1068 | |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 1069 | /** |
| 1070 | * For special services that are bound to by system code, this is |
| 1071 | * the package that holds the binding. |
| 1072 | */ |
| 1073 | public String clientPackage; |
| 1074 | |
| 1075 | /** |
| 1076 | * For special services that are bound to by system code, this is |
| 1077 | * a string resource providing a user-visible label for who the |
| 1078 | * client is. |
| 1079 | */ |
| 1080 | public int clientLabel; |
| 1081 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1082 | public RunningServiceInfo() { |
| 1083 | } |
| 1084 | |
| 1085 | public int describeContents() { |
| 1086 | return 0; |
| 1087 | } |
| 1088 | |
| 1089 | public void writeToParcel(Parcel dest, int flags) { |
| 1090 | ComponentName.writeToParcel(service, dest); |
| 1091 | dest.writeInt(pid); |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 1092 | dest.writeInt(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1093 | dest.writeString(process); |
| 1094 | dest.writeInt(foreground ? 1 : 0); |
| 1095 | dest.writeLong(activeSince); |
| 1096 | dest.writeInt(started ? 1 : 0); |
| 1097 | dest.writeInt(clientCount); |
| 1098 | dest.writeInt(crashCount); |
| 1099 | dest.writeLong(lastActivityTime); |
| 1100 | dest.writeLong(restarting); |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 1101 | dest.writeInt(this.flags); |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 1102 | dest.writeString(clientPackage); |
| 1103 | dest.writeInt(clientLabel); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | public void readFromParcel(Parcel source) { |
| 1107 | service = ComponentName.readFromParcel(source); |
| 1108 | pid = source.readInt(); |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 1109 | uid = source.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1110 | process = source.readString(); |
| 1111 | foreground = source.readInt() != 0; |
| 1112 | activeSince = source.readLong(); |
| 1113 | started = source.readInt() != 0; |
| 1114 | clientCount = source.readInt(); |
| 1115 | crashCount = source.readInt(); |
| 1116 | lastActivityTime = source.readLong(); |
| 1117 | restarting = source.readLong(); |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 1118 | flags = source.readInt(); |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 1119 | clientPackage = source.readString(); |
| 1120 | clientLabel = source.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | public static final Creator<RunningServiceInfo> CREATOR = new Creator<RunningServiceInfo>() { |
| 1124 | public RunningServiceInfo createFromParcel(Parcel source) { |
| 1125 | return new RunningServiceInfo(source); |
| 1126 | } |
| 1127 | public RunningServiceInfo[] newArray(int size) { |
| 1128 | return new RunningServiceInfo[size]; |
| 1129 | } |
| 1130 | }; |
| 1131 | |
| 1132 | private RunningServiceInfo(Parcel source) { |
| 1133 | readFromParcel(source); |
| 1134 | } |
| 1135 | } |
| 1136 | |
| 1137 | /** |
| 1138 | * Return a list of the services that are currently running. |
Dianne Hackborn | c5bf758 | 2012-04-25 19:12:07 -0700 | [diff] [blame] | 1139 | * |
| 1140 | * <p><b>Note: this method is only intended for debugging or implementing |
| 1141 | * service management type user interfaces.</b></p> |
| 1142 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1143 | * @param maxNum The maximum number of entries to return in the list. The |
| 1144 | * actual number returned may be smaller, depending on how many services |
| 1145 | * are running. |
| 1146 | * |
| 1147 | * @return Returns a list of RunningServiceInfo records describing each of |
| 1148 | * the running tasks. |
| 1149 | */ |
| 1150 | public List<RunningServiceInfo> getRunningServices(int maxNum) |
| 1151 | throws SecurityException { |
| 1152 | try { |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 1153 | return ActivityManagerNative.getDefault() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1154 | .getServices(maxNum, 0); |
| 1155 | } catch (RemoteException e) { |
| 1156 | // System dead, we will be dead too soon! |
| 1157 | return null; |
| 1158 | } |
| 1159 | } |
| 1160 | |
| 1161 | /** |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 1162 | * Returns a PendingIntent you can start to show a control panel for the |
| 1163 | * given running service. If the service does not have a control panel, |
| 1164 | * null is returned. |
| 1165 | */ |
| 1166 | public PendingIntent getRunningServiceControlPanel(ComponentName service) |
| 1167 | throws SecurityException { |
| 1168 | try { |
| 1169 | return ActivityManagerNative.getDefault() |
| 1170 | .getRunningServiceControlPanel(service); |
| 1171 | } catch (RemoteException e) { |
| 1172 | // System dead, we will be dead too soon! |
| 1173 | return null; |
| 1174 | } |
| 1175 | } |
| 1176 | |
| 1177 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1178 | * Information you can retrieve about the available memory through |
| 1179 | * {@link ActivityManager#getMemoryInfo}. |
| 1180 | */ |
| 1181 | public static class MemoryInfo implements Parcelable { |
| 1182 | /** |
Dianne Hackborn | 59325eb | 2012-05-09 18:45:20 -0700 | [diff] [blame] | 1183 | * 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] | 1184 | * be considered absolute: due to the nature of the kernel, a significant |
| 1185 | * portion of this memory is actually in use and needed for the overall |
| 1186 | * system to run well. |
| 1187 | */ |
| 1188 | public long availMem; |
Dianne Hackborn | 59325eb | 2012-05-09 18:45:20 -0700 | [diff] [blame] | 1189 | |
| 1190 | /** |
| 1191 | * The total memory accessible by the kernel. This is basically the |
| 1192 | * RAM size of the device, not including below-kernel fixed allocations |
| 1193 | * like DMA buffers, RAM for the baseband CPU, etc. |
| 1194 | */ |
| 1195 | public long totalMem; |
| 1196 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1197 | /** |
| 1198 | * The threshold of {@link #availMem} at which we consider memory to be |
| 1199 | * low and start killing background services and other non-extraneous |
| 1200 | * processes. |
| 1201 | */ |
| 1202 | public long threshold; |
| 1203 | |
| 1204 | /** |
| 1205 | * Set to true if the system considers itself to currently be in a low |
| 1206 | * memory situation. |
| 1207 | */ |
| 1208 | public boolean lowMemory; |
| 1209 | |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 1210 | /** @hide */ |
| 1211 | public long hiddenAppThreshold; |
| 1212 | /** @hide */ |
| 1213 | public long secondaryServerThreshold; |
| 1214 | /** @hide */ |
| 1215 | public long visibleAppThreshold; |
| 1216 | /** @hide */ |
| 1217 | public long foregroundAppThreshold; |
| 1218 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1219 | public MemoryInfo() { |
| 1220 | } |
| 1221 | |
| 1222 | public int describeContents() { |
| 1223 | return 0; |
| 1224 | } |
| 1225 | |
| 1226 | public void writeToParcel(Parcel dest, int flags) { |
| 1227 | dest.writeLong(availMem); |
Dianne Hackborn | 59325eb | 2012-05-09 18:45:20 -0700 | [diff] [blame] | 1228 | dest.writeLong(totalMem); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1229 | dest.writeLong(threshold); |
| 1230 | dest.writeInt(lowMemory ? 1 : 0); |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 1231 | dest.writeLong(hiddenAppThreshold); |
| 1232 | dest.writeLong(secondaryServerThreshold); |
| 1233 | dest.writeLong(visibleAppThreshold); |
| 1234 | dest.writeLong(foregroundAppThreshold); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1235 | } |
| 1236 | |
| 1237 | public void readFromParcel(Parcel source) { |
| 1238 | availMem = source.readLong(); |
Dianne Hackborn | 59325eb | 2012-05-09 18:45:20 -0700 | [diff] [blame] | 1239 | totalMem = source.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1240 | threshold = source.readLong(); |
| 1241 | lowMemory = source.readInt() != 0; |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 1242 | hiddenAppThreshold = source.readLong(); |
| 1243 | secondaryServerThreshold = source.readLong(); |
| 1244 | visibleAppThreshold = source.readLong(); |
| 1245 | foregroundAppThreshold = source.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1246 | } |
| 1247 | |
| 1248 | public static final Creator<MemoryInfo> CREATOR |
| 1249 | = new Creator<MemoryInfo>() { |
| 1250 | public MemoryInfo createFromParcel(Parcel source) { |
| 1251 | return new MemoryInfo(source); |
| 1252 | } |
| 1253 | public MemoryInfo[] newArray(int size) { |
| 1254 | return new MemoryInfo[size]; |
| 1255 | } |
| 1256 | }; |
| 1257 | |
| 1258 | private MemoryInfo(Parcel source) { |
| 1259 | readFromParcel(source); |
| 1260 | } |
| 1261 | } |
| 1262 | |
Dianne Hackborn | c5bf758 | 2012-04-25 19:12:07 -0700 | [diff] [blame] | 1263 | /** |
| 1264 | * Return general information about the memory state of the system. This |
| 1265 | * can be used to help decide how to manage your own memory, though note |
| 1266 | * that polling is not recommended and |
| 1267 | * {@link android.content.ComponentCallbacks2#onTrimMemory(int) |
| 1268 | * ComponentCallbacks2.onTrimMemory(int)} is the preferred way to do this. |
| 1269 | * Also see {@link #getMyMemoryState} for how to retrieve the current trim |
| 1270 | * level of your process as needed, which gives a better hint for how to |
| 1271 | * manage its memory. |
| 1272 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1273 | public void getMemoryInfo(MemoryInfo outInfo) { |
| 1274 | try { |
| 1275 | ActivityManagerNative.getDefault().getMemoryInfo(outInfo); |
| 1276 | } catch (RemoteException e) { |
| 1277 | } |
| 1278 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1279 | |
Craig Mautner | 5ff1210 | 2013-05-24 12:50:15 -0700 | [diff] [blame] | 1280 | /** |
| 1281 | * Information you can retrieve about the WindowManager StackBox hierarchy. |
| 1282 | * @hide |
| 1283 | */ |
| 1284 | public static class StackBoxInfo implements Parcelable { |
| 1285 | public int stackBoxId; |
| 1286 | public float weight; |
| 1287 | public boolean vertical; |
| 1288 | public Rect bounds; |
| 1289 | public StackBoxInfo[] children; |
| 1290 | public int stackId; |
| 1291 | public StackInfo stack; |
| 1292 | |
| 1293 | @Override |
| 1294 | public int describeContents() { |
| 1295 | return 0; |
| 1296 | } |
| 1297 | |
| 1298 | @Override |
| 1299 | public void writeToParcel(Parcel dest, int flags) { |
| 1300 | dest.writeInt(stackBoxId); |
| 1301 | dest.writeFloat(weight); |
| 1302 | dest.writeInt(vertical ? 1 : 0); |
| 1303 | bounds.writeToParcel(dest, flags); |
| 1304 | dest.writeInt(stackId); |
| 1305 | if (children != null) { |
| 1306 | children[0].writeToParcel(dest, flags); |
| 1307 | children[1].writeToParcel(dest, flags); |
| 1308 | } else { |
| 1309 | stack.writeToParcel(dest, flags); |
| 1310 | } |
| 1311 | } |
| 1312 | |
| 1313 | public void readFromParcel(Parcel source) { |
| 1314 | stackBoxId = source.readInt(); |
| 1315 | weight = source.readFloat(); |
| 1316 | vertical = source.readInt() == 1; |
| 1317 | bounds = Rect.CREATOR.createFromParcel(source); |
| 1318 | stackId = source.readInt(); |
| 1319 | if (stackId == -1) { |
| 1320 | children = new StackBoxInfo[2]; |
| 1321 | children[0] = StackBoxInfo.CREATOR.createFromParcel(source); |
| 1322 | children[1] = StackBoxInfo.CREATOR.createFromParcel(source); |
| 1323 | } else { |
| 1324 | stack = StackInfo.CREATOR.createFromParcel(source); |
| 1325 | } |
| 1326 | } |
| 1327 | |
| 1328 | public static final Creator<StackBoxInfo> CREATOR = |
| 1329 | new Creator<ActivityManager.StackBoxInfo>() { |
| 1330 | |
| 1331 | @Override |
| 1332 | public StackBoxInfo createFromParcel(Parcel source) { |
| 1333 | return new StackBoxInfo(source); |
| 1334 | } |
| 1335 | |
| 1336 | @Override |
| 1337 | public StackBoxInfo[] newArray(int size) { |
| 1338 | return new StackBoxInfo[size]; |
| 1339 | } |
| 1340 | }; |
| 1341 | |
| 1342 | public StackBoxInfo() { |
| 1343 | } |
| 1344 | |
| 1345 | public StackBoxInfo(Parcel source) { |
| 1346 | readFromParcel(source); |
| 1347 | } |
| 1348 | |
| 1349 | public String toString(String prefix) { |
| 1350 | StringBuilder sb = new StringBuilder(256); |
| 1351 | sb.append(prefix); sb.append("Box id=" + stackBoxId); sb.append(" weight=" + weight); |
| 1352 | sb.append(" vertical=" + vertical); sb.append(" bounds=" + bounds.toShortString()); |
| 1353 | sb.append("\n"); |
| 1354 | if (children != null) { |
| 1355 | sb.append(prefix); sb.append("First child=\n"); |
| 1356 | sb.append(children[0].toString(prefix + " ")); |
| 1357 | sb.append(prefix); sb.append("Second child=\n"); |
| 1358 | sb.append(children[1].toString(prefix + " ")); |
| 1359 | } else { |
| 1360 | sb.append(prefix); sb.append("Stack=\n"); |
| 1361 | sb.append(stack.toString(prefix + " ")); |
| 1362 | } |
| 1363 | return sb.toString(); |
| 1364 | } |
| 1365 | |
| 1366 | @Override |
| 1367 | public String toString() { |
| 1368 | return toString(""); |
| 1369 | } |
| 1370 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1371 | |
| 1372 | /** |
| 1373 | * Information you can retrieve about an ActivityStack in the system. |
| 1374 | * @hide |
| 1375 | */ |
| 1376 | public static class StackInfo implements Parcelable { |
| 1377 | public int stackId; |
| 1378 | public Rect bounds; |
| 1379 | public int[] taskIds; |
| 1380 | public String[] taskNames; |
| 1381 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1382 | @Override |
| 1383 | public int describeContents() { |
| 1384 | return 0; |
| 1385 | } |
| 1386 | |
| 1387 | @Override |
| 1388 | public void writeToParcel(Parcel dest, int flags) { |
| 1389 | dest.writeInt(stackId); |
| 1390 | dest.writeInt(bounds.left); |
| 1391 | dest.writeInt(bounds.top); |
| 1392 | dest.writeInt(bounds.right); |
| 1393 | dest.writeInt(bounds.bottom); |
| 1394 | dest.writeIntArray(taskIds); |
| 1395 | dest.writeStringArray(taskNames); |
| 1396 | } |
| 1397 | |
| 1398 | public void readFromParcel(Parcel source) { |
| 1399 | stackId = source.readInt(); |
| 1400 | bounds = new Rect( |
| 1401 | source.readInt(), source.readInt(), source.readInt(), source.readInt()); |
| 1402 | taskIds = source.createIntArray(); |
| 1403 | taskNames = source.createStringArray(); |
| 1404 | } |
| 1405 | |
| 1406 | public static final Creator<StackInfo> CREATOR = new Creator<StackInfo>() { |
| 1407 | @Override |
| 1408 | public StackInfo createFromParcel(Parcel source) { |
| 1409 | return new StackInfo(source); |
| 1410 | } |
| 1411 | @Override |
| 1412 | public StackInfo[] newArray(int size) { |
| 1413 | return new StackInfo[size]; |
| 1414 | } |
| 1415 | }; |
| 1416 | |
Craig Mautner | 5ff1210 | 2013-05-24 12:50:15 -0700 | [diff] [blame] | 1417 | public StackInfo() { |
| 1418 | } |
| 1419 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1420 | private StackInfo(Parcel source) { |
| 1421 | readFromParcel(source); |
| 1422 | } |
| 1423 | |
Craig Mautner | 5ff1210 | 2013-05-24 12:50:15 -0700 | [diff] [blame] | 1424 | public String toString(String prefix) { |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1425 | StringBuilder sb = new StringBuilder(256); |
Craig Mautner | 5ff1210 | 2013-05-24 12:50:15 -0700 | [diff] [blame] | 1426 | sb.append(prefix); sb.append("Stack id="); sb.append(stackId); |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1427 | sb.append(" bounds="); sb.append(bounds.toShortString()); sb.append("\n"); |
Craig Mautner | 5ff1210 | 2013-05-24 12:50:15 -0700 | [diff] [blame] | 1428 | prefix = prefix + " "; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1429 | for (int i = 0; i < taskIds.length; ++i) { |
| 1430 | sb.append(prefix); sb.append("taskId="); sb.append(taskIds[i]); |
| 1431 | sb.append(": "); sb.append(taskNames[i]); sb.append("\n"); |
| 1432 | } |
| 1433 | return sb.toString(); |
| 1434 | } |
Craig Mautner | 5ff1210 | 2013-05-24 12:50:15 -0700 | [diff] [blame] | 1435 | |
| 1436 | @Override |
| 1437 | public String toString() { |
| 1438 | return toString(""); |
| 1439 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1440 | } |
| 1441 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1442 | /** |
| 1443 | * @hide |
| 1444 | */ |
| 1445 | public boolean clearApplicationUserData(String packageName, IPackageDataObserver observer) { |
| 1446 | try { |
| 1447 | return ActivityManagerNative.getDefault().clearApplicationUserData(packageName, |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 1448 | observer, UserHandle.myUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1449 | } catch (RemoteException e) { |
| 1450 | return false; |
| 1451 | } |
| 1452 | } |
Christopher Tate | a366424 | 2013-06-26 15:00:18 -0700 | [diff] [blame] | 1453 | |
| 1454 | /** |
| 1455 | * Permits an application to erase its own data from disk. This is equivalent to |
| 1456 | * the user choosing to clear the app's data from within the device settings UI. |
| 1457 | * |
| 1458 | * @return {@code true} if the application successfully requested that the application's |
| 1459 | * data be erased; {@code false} otherwise. |
| 1460 | */ |
| 1461 | public boolean clearApplicationUserData() { |
| 1462 | return clearApplicationUserData(mContext.getPackageName(), null); |
| 1463 | } |
| 1464 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1465 | /** |
| 1466 | * Information you can retrieve about any processes that are in an error condition. |
| 1467 | */ |
| 1468 | public static class ProcessErrorStateInfo implements Parcelable { |
| 1469 | /** |
| 1470 | * Condition codes |
| 1471 | */ |
| 1472 | public static final int NO_ERROR = 0; |
| 1473 | public static final int CRASHED = 1; |
| 1474 | public static final int NOT_RESPONDING = 2; |
| 1475 | |
| 1476 | /** |
| 1477 | * The condition that the process is in. |
| 1478 | */ |
| 1479 | public int condition; |
| 1480 | |
| 1481 | /** |
| 1482 | * The process name in which the crash or error occurred. |
| 1483 | */ |
| 1484 | public String processName; |
| 1485 | |
| 1486 | /** |
| 1487 | * The pid of this process; 0 if none |
| 1488 | */ |
| 1489 | public int pid; |
| 1490 | |
| 1491 | /** |
| 1492 | * The kernel user-ID that has been assigned to this process; |
| 1493 | * currently this is not a unique ID (multiple applications can have |
| 1494 | * the same uid). |
| 1495 | */ |
| 1496 | public int uid; |
| 1497 | |
| 1498 | /** |
Dan Egnor | 60d8762 | 2009-12-16 16:32:58 -0800 | [diff] [blame] | 1499 | * 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] | 1500 | */ |
| 1501 | public String tag; |
| 1502 | |
| 1503 | /** |
| 1504 | * A short message describing the error condition. |
| 1505 | */ |
| 1506 | public String shortMsg; |
| 1507 | |
| 1508 | /** |
| 1509 | * A long message describing the error condition. |
| 1510 | */ |
| 1511 | public String longMsg; |
| 1512 | |
| 1513 | /** |
Dan Egnor | b7f0367 | 2009-12-09 16:22:32 -0800 | [diff] [blame] | 1514 | * 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] | 1515 | */ |
Dan Egnor | b7f0367 | 2009-12-09 16:22:32 -0800 | [diff] [blame] | 1516 | public String stackTrace; |
| 1517 | |
| 1518 | /** |
| 1519 | * to be deprecated: This value will always be null. |
| 1520 | */ |
| 1521 | public byte[] crashData = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1522 | |
| 1523 | public ProcessErrorStateInfo() { |
| 1524 | } |
| 1525 | |
Craig Mautner | 5ff1210 | 2013-05-24 12:50:15 -0700 | [diff] [blame] | 1526 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1527 | public int describeContents() { |
| 1528 | return 0; |
| 1529 | } |
| 1530 | |
Craig Mautner | 5ff1210 | 2013-05-24 12:50:15 -0700 | [diff] [blame] | 1531 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1532 | public void writeToParcel(Parcel dest, int flags) { |
| 1533 | dest.writeInt(condition); |
| 1534 | dest.writeString(processName); |
| 1535 | dest.writeInt(pid); |
| 1536 | dest.writeInt(uid); |
| 1537 | dest.writeString(tag); |
| 1538 | dest.writeString(shortMsg); |
| 1539 | dest.writeString(longMsg); |
Dan Egnor | b7f0367 | 2009-12-09 16:22:32 -0800 | [diff] [blame] | 1540 | dest.writeString(stackTrace); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1541 | } |
Craig Mautner | 5ff1210 | 2013-05-24 12:50:15 -0700 | [diff] [blame] | 1542 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1543 | public void readFromParcel(Parcel source) { |
| 1544 | condition = source.readInt(); |
| 1545 | processName = source.readString(); |
| 1546 | pid = source.readInt(); |
| 1547 | uid = source.readInt(); |
| 1548 | tag = source.readString(); |
| 1549 | shortMsg = source.readString(); |
| 1550 | longMsg = source.readString(); |
Dan Egnor | b7f0367 | 2009-12-09 16:22:32 -0800 | [diff] [blame] | 1551 | stackTrace = source.readString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1552 | } |
| 1553 | |
| 1554 | public static final Creator<ProcessErrorStateInfo> CREATOR = |
| 1555 | new Creator<ProcessErrorStateInfo>() { |
| 1556 | public ProcessErrorStateInfo createFromParcel(Parcel source) { |
| 1557 | return new ProcessErrorStateInfo(source); |
| 1558 | } |
| 1559 | public ProcessErrorStateInfo[] newArray(int size) { |
| 1560 | return new ProcessErrorStateInfo[size]; |
| 1561 | } |
| 1562 | }; |
| 1563 | |
| 1564 | private ProcessErrorStateInfo(Parcel source) { |
| 1565 | readFromParcel(source); |
| 1566 | } |
| 1567 | } |
| 1568 | |
| 1569 | /** |
| 1570 | * Returns a list of any processes that are currently in an error condition. The result |
| 1571 | * will be null if all processes are running properly at this time. |
| 1572 | * |
| 1573 | * @return Returns a list of ProcessErrorStateInfo records, or null if there are no |
| 1574 | * current error conditions (it will not return an empty list). This list ordering is not |
| 1575 | * specified. |
| 1576 | */ |
| 1577 | public List<ProcessErrorStateInfo> getProcessesInErrorState() { |
| 1578 | try { |
| 1579 | return ActivityManagerNative.getDefault().getProcessesInErrorState(); |
| 1580 | } catch (RemoteException e) { |
| 1581 | return null; |
| 1582 | } |
| 1583 | } |
| 1584 | |
| 1585 | /** |
| 1586 | * Information you can retrieve about a running process. |
| 1587 | */ |
| 1588 | public static class RunningAppProcessInfo implements Parcelable { |
| 1589 | /** |
| 1590 | * The name of the process that this object is associated with |
| 1591 | */ |
| 1592 | public String processName; |
| 1593 | |
| 1594 | /** |
| 1595 | * The pid of this process; 0 if none |
| 1596 | */ |
| 1597 | public int pid; |
| 1598 | |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 1599 | /** |
| 1600 | * The user id of this process. |
| 1601 | */ |
| 1602 | public int uid; |
| 1603 | |
Dianne Hackborn | baf42c6 | 2010-06-24 11:23:39 -0700 | [diff] [blame] | 1604 | /** |
| 1605 | * All packages that have been loaded into the process. |
| 1606 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1607 | public String pkgList[]; |
| 1608 | |
| 1609 | /** |
Dianne Hackborn | 482566e | 2010-09-03 12:51:28 -0700 | [diff] [blame] | 1610 | * Constant for {@link #flags}: this is an app that is unable to |
| 1611 | * correctly save its state when going to the background, |
| 1612 | * so it can not be killed while in the background. |
| 1613 | * @hide |
Dianne Hackborn | baf42c6 | 2010-06-24 11:23:39 -0700 | [diff] [blame] | 1614 | */ |
Dianne Hackborn | 482566e | 2010-09-03 12:51:28 -0700 | [diff] [blame] | 1615 | public static final int FLAG_CANT_SAVE_STATE = 1<<0; |
Dianne Hackborn | baf42c6 | 2010-06-24 11:23:39 -0700 | [diff] [blame] | 1616 | |
| 1617 | /** |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 1618 | * Constant for {@link #flags}: this process is associated with a |
| 1619 | * persistent system app. |
| 1620 | * @hide |
| 1621 | */ |
| 1622 | public static final int FLAG_PERSISTENT = 1<<1; |
| 1623 | |
| 1624 | /** |
Dianne Hackborn | 0c38049 | 2012-08-20 17:23:30 -0700 | [diff] [blame] | 1625 | * Constant for {@link #flags}: this process is associated with a |
| 1626 | * persistent system app. |
| 1627 | * @hide |
| 1628 | */ |
| 1629 | public static final int FLAG_HAS_ACTIVITIES = 1<<2; |
| 1630 | |
| 1631 | /** |
Dianne Hackborn | baf42c6 | 2010-06-24 11:23:39 -0700 | [diff] [blame] | 1632 | * Flags of information. May be any of |
Dianne Hackborn | 482566e | 2010-09-03 12:51:28 -0700 | [diff] [blame] | 1633 | * {@link #FLAG_CANT_SAVE_STATE}. |
| 1634 | * @hide |
Dianne Hackborn | baf42c6 | 2010-06-24 11:23:39 -0700 | [diff] [blame] | 1635 | */ |
| 1636 | public int flags; |
Dianne Hackborn | 27ff913 | 2012-03-06 14:57:58 -0800 | [diff] [blame] | 1637 | |
| 1638 | /** |
| 1639 | * Last memory trim level reported to the process: corresponds to |
| 1640 | * the values supplied to {@link android.content.ComponentCallbacks2#onTrimMemory(int) |
| 1641 | * ComponentCallbacks2.onTrimMemory(int)}. |
| 1642 | */ |
| 1643 | public int lastTrimLevel; |
| 1644 | |
Dianne Hackborn | baf42c6 | 2010-06-24 11:23:39 -0700 | [diff] [blame] | 1645 | /** |
Dianne Hackborn | a93c2c1 | 2012-05-31 15:29:36 -0700 | [diff] [blame] | 1646 | * Constant for {@link #importance}: this is a persistent process. |
| 1647 | * Only used when reporting to process observers. |
| 1648 | * @hide |
| 1649 | */ |
| 1650 | public static final int IMPORTANCE_PERSISTENT = 50; |
| 1651 | |
| 1652 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1653 | * Constant for {@link #importance}: this process is running the |
| 1654 | * foreground UI. |
| 1655 | */ |
| 1656 | public static final int IMPORTANCE_FOREGROUND = 100; |
| 1657 | |
| 1658 | /** |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1659 | * Constant for {@link #importance}: this process is running something |
| 1660 | * that is actively visible to the user, though not in the immediate |
| 1661 | * foreground. |
Dianne Hackborn | 860755f | 2010-06-03 18:47:52 -0700 | [diff] [blame] | 1662 | */ |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1663 | public static final int IMPORTANCE_VISIBLE = 200; |
Dianne Hackborn | 860755f | 2010-06-03 18:47:52 -0700 | [diff] [blame] | 1664 | |
| 1665 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1666 | * Constant for {@link #importance}: this process is running something |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1667 | * that is considered to be actively perceptible to the user. An |
| 1668 | * example would be an application performing background music playback. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1669 | */ |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1670 | public static final int IMPORTANCE_PERCEPTIBLE = 130; |
| 1671 | |
| 1672 | /** |
Dianne Hackborn | 5383f50 | 2010-10-22 12:59:20 -0700 | [diff] [blame] | 1673 | * Constant for {@link #importance}: this process is running an |
| 1674 | * application that can not save its state, and thus can't be killed |
| 1675 | * while in the background. |
| 1676 | * @hide |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1677 | */ |
Dianne Hackborn | 5383f50 | 2010-10-22 12:59:20 -0700 | [diff] [blame] | 1678 | public static final int IMPORTANCE_CANT_SAVE_STATE = 170; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1679 | |
| 1680 | /** |
| 1681 | * Constant for {@link #importance}: this process is contains services |
| 1682 | * that should remain running. |
| 1683 | */ |
| 1684 | public static final int IMPORTANCE_SERVICE = 300; |
| 1685 | |
| 1686 | /** |
| 1687 | * Constant for {@link #importance}: this process process contains |
| 1688 | * background code that is expendable. |
| 1689 | */ |
| 1690 | public static final int IMPORTANCE_BACKGROUND = 400; |
| 1691 | |
| 1692 | /** |
| 1693 | * Constant for {@link #importance}: this process is empty of any |
| 1694 | * actively running code. |
| 1695 | */ |
| 1696 | public static final int IMPORTANCE_EMPTY = 500; |
| 1697 | |
| 1698 | /** |
| 1699 | * The relative importance level that the system places on this |
| 1700 | * process. May be one of {@link #IMPORTANCE_FOREGROUND}, |
| 1701 | * {@link #IMPORTANCE_VISIBLE}, {@link #IMPORTANCE_SERVICE}, |
| 1702 | * {@link #IMPORTANCE_BACKGROUND}, or {@link #IMPORTANCE_EMPTY}. These |
| 1703 | * constants are numbered so that "more important" values are always |
| 1704 | * smaller than "less important" values. |
| 1705 | */ |
| 1706 | public int importance; |
| 1707 | |
| 1708 | /** |
| 1709 | * An additional ordering within a particular {@link #importance} |
| 1710 | * category, providing finer-grained information about the relative |
| 1711 | * utility of processes within a category. This number means nothing |
| 1712 | * except that a smaller values are more recently used (and thus |
| 1713 | * more important). Currently an LRU value is only maintained for |
| 1714 | * the {@link #IMPORTANCE_BACKGROUND} category, though others may |
| 1715 | * be maintained in the future. |
| 1716 | */ |
| 1717 | public int lru; |
Dianne Hackborn | 27ff913 | 2012-03-06 14:57:58 -0800 | [diff] [blame] | 1718 | |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 1719 | /** |
| 1720 | * Constant for {@link #importanceReasonCode}: nothing special has |
| 1721 | * been specified for the reason for this level. |
| 1722 | */ |
| 1723 | public static final int REASON_UNKNOWN = 0; |
| 1724 | |
| 1725 | /** |
| 1726 | * Constant for {@link #importanceReasonCode}: one of the application's |
| 1727 | * content providers is being used by another process. The pid of |
| 1728 | * the client process is in {@link #importanceReasonPid} and the |
| 1729 | * target provider in this process is in |
| 1730 | * {@link #importanceReasonComponent}. |
| 1731 | */ |
| 1732 | public static final int REASON_PROVIDER_IN_USE = 1; |
| 1733 | |
| 1734 | /** |
| 1735 | * Constant for {@link #importanceReasonCode}: one of the application's |
| 1736 | * content providers is being used by another process. The pid of |
| 1737 | * the client process is in {@link #importanceReasonPid} and the |
| 1738 | * target provider in this process is in |
| 1739 | * {@link #importanceReasonComponent}. |
| 1740 | */ |
| 1741 | public static final int REASON_SERVICE_IN_USE = 2; |
| 1742 | |
| 1743 | /** |
| 1744 | * The reason for {@link #importance}, if any. |
| 1745 | */ |
| 1746 | public int importanceReasonCode; |
| 1747 | |
| 1748 | /** |
| 1749 | * For the specified values of {@link #importanceReasonCode}, this |
| 1750 | * is the process ID of the other process that is a client of this |
| 1751 | * process. This will be 0 if no other process is using this one. |
| 1752 | */ |
| 1753 | public int importanceReasonPid; |
| 1754 | |
| 1755 | /** |
| 1756 | * For the specified values of {@link #importanceReasonCode}, this |
| 1757 | * is the name of the component that is being used in this process. |
| 1758 | */ |
| 1759 | public ComponentName importanceReasonComponent; |
| 1760 | |
Dianne Hackborn | 905577f | 2011-09-07 18:31:28 -0700 | [diff] [blame] | 1761 | /** |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 1762 | * When {@link #importanceReasonPid} is non-0, this is the importance |
Dianne Hackborn | 905577f | 2011-09-07 18:31:28 -0700 | [diff] [blame] | 1763 | * of the other pid. @hide |
| 1764 | */ |
| 1765 | public int importanceReasonImportance; |
| 1766 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1767 | public RunningAppProcessInfo() { |
| 1768 | importance = IMPORTANCE_FOREGROUND; |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 1769 | importanceReasonCode = REASON_UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1770 | } |
| 1771 | |
| 1772 | public RunningAppProcessInfo(String pProcessName, int pPid, String pArr[]) { |
| 1773 | processName = pProcessName; |
| 1774 | pid = pPid; |
| 1775 | pkgList = pArr; |
| 1776 | } |
| 1777 | |
| 1778 | public int describeContents() { |
| 1779 | return 0; |
| 1780 | } |
| 1781 | |
| 1782 | public void writeToParcel(Parcel dest, int flags) { |
| 1783 | dest.writeString(processName); |
| 1784 | dest.writeInt(pid); |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 1785 | dest.writeInt(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1786 | dest.writeStringArray(pkgList); |
Dianne Hackborn | baf42c6 | 2010-06-24 11:23:39 -0700 | [diff] [blame] | 1787 | dest.writeInt(this.flags); |
Dianne Hackborn | 27ff913 | 2012-03-06 14:57:58 -0800 | [diff] [blame] | 1788 | dest.writeInt(lastTrimLevel); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1789 | dest.writeInt(importance); |
| 1790 | dest.writeInt(lru); |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 1791 | dest.writeInt(importanceReasonCode); |
| 1792 | dest.writeInt(importanceReasonPid); |
| 1793 | ComponentName.writeToParcel(importanceReasonComponent, dest); |
Dianne Hackborn | 905577f | 2011-09-07 18:31:28 -0700 | [diff] [blame] | 1794 | dest.writeInt(importanceReasonImportance); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1795 | } |
| 1796 | |
| 1797 | public void readFromParcel(Parcel source) { |
| 1798 | processName = source.readString(); |
| 1799 | pid = source.readInt(); |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 1800 | uid = source.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1801 | pkgList = source.readStringArray(); |
Dianne Hackborn | baf42c6 | 2010-06-24 11:23:39 -0700 | [diff] [blame] | 1802 | flags = source.readInt(); |
Dianne Hackborn | 27ff913 | 2012-03-06 14:57:58 -0800 | [diff] [blame] | 1803 | lastTrimLevel = source.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1804 | importance = source.readInt(); |
| 1805 | lru = source.readInt(); |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 1806 | importanceReasonCode = source.readInt(); |
| 1807 | importanceReasonPid = source.readInt(); |
| 1808 | importanceReasonComponent = ComponentName.readFromParcel(source); |
Dianne Hackborn | 905577f | 2011-09-07 18:31:28 -0700 | [diff] [blame] | 1809 | importanceReasonImportance = source.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1810 | } |
| 1811 | |
| 1812 | public static final Creator<RunningAppProcessInfo> CREATOR = |
| 1813 | new Creator<RunningAppProcessInfo>() { |
| 1814 | public RunningAppProcessInfo createFromParcel(Parcel source) { |
| 1815 | return new RunningAppProcessInfo(source); |
| 1816 | } |
| 1817 | public RunningAppProcessInfo[] newArray(int size) { |
| 1818 | return new RunningAppProcessInfo[size]; |
| 1819 | } |
| 1820 | }; |
| 1821 | |
| 1822 | private RunningAppProcessInfo(Parcel source) { |
| 1823 | readFromParcel(source); |
| 1824 | } |
| 1825 | } |
| 1826 | |
| 1827 | /** |
Suchi Amalapurapu | f7f5dda | 2010-03-23 10:34:28 -0700 | [diff] [blame] | 1828 | * Returns a list of application processes installed on external media |
| 1829 | * that are running on the device. |
| 1830 | * |
Dianne Hackborn | c5bf758 | 2012-04-25 19:12:07 -0700 | [diff] [blame] | 1831 | * <p><b>Note: this method is only intended for debugging or building |
| 1832 | * a user-facing process management UI.</b></p> |
| 1833 | * |
Suchi Amalapurapu | f7f5dda | 2010-03-23 10:34:28 -0700 | [diff] [blame] | 1834 | * @return Returns a list of ApplicationInfo records, or null if none |
| 1835 | * This list ordering is not specified. |
| 1836 | * @hide |
| 1837 | */ |
| 1838 | public List<ApplicationInfo> getRunningExternalApplications() { |
| 1839 | try { |
| 1840 | return ActivityManagerNative.getDefault().getRunningExternalApplications(); |
| 1841 | } catch (RemoteException e) { |
| 1842 | return null; |
| 1843 | } |
| 1844 | } |
| 1845 | |
| 1846 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1847 | * Returns a list of application processes that are running on the device. |
Dianne Hackborn | c5bf758 | 2012-04-25 19:12:07 -0700 | [diff] [blame] | 1848 | * |
| 1849 | * <p><b>Note: this method is only intended for debugging or building |
| 1850 | * a user-facing process management UI.</b></p> |
| 1851 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1852 | * @return Returns a list of RunningAppProcessInfo records, or null if there are no |
| 1853 | * running processes (it will not return an empty list). This list ordering is not |
| 1854 | * specified. |
| 1855 | */ |
| 1856 | public List<RunningAppProcessInfo> getRunningAppProcesses() { |
| 1857 | try { |
| 1858 | return ActivityManagerNative.getDefault().getRunningAppProcesses(); |
| 1859 | } catch (RemoteException e) { |
| 1860 | return null; |
| 1861 | } |
| 1862 | } |
Dianne Hackborn | 27ff913 | 2012-03-06 14:57:58 -0800 | [diff] [blame] | 1863 | |
| 1864 | /** |
| 1865 | * Return global memory state information for the calling process. This |
| 1866 | * does not fill in all fields of the {@link RunningAppProcessInfo}. The |
| 1867 | * only fields that will be filled in are |
| 1868 | * {@link RunningAppProcessInfo#pid}, |
| 1869 | * {@link RunningAppProcessInfo#uid}, |
| 1870 | * {@link RunningAppProcessInfo#lastTrimLevel}, |
| 1871 | * {@link RunningAppProcessInfo#importance}, |
| 1872 | * {@link RunningAppProcessInfo#lru}, and |
| 1873 | * {@link RunningAppProcessInfo#importanceReasonCode}. |
| 1874 | */ |
| 1875 | static public void getMyMemoryState(RunningAppProcessInfo outState) { |
| 1876 | try { |
| 1877 | ActivityManagerNative.getDefault().getMyMemoryState(outState); |
| 1878 | } catch (RemoteException e) { |
| 1879 | } |
| 1880 | } |
| 1881 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1882 | /** |
Dianne Hackborn | 4f21c4c | 2009-09-17 10:24:05 -0700 | [diff] [blame] | 1883 | * Return information about the memory usage of one or more processes. |
Dianne Hackborn | c5bf758 | 2012-04-25 19:12:07 -0700 | [diff] [blame] | 1884 | * |
| 1885 | * <p><b>Note: this method is only intended for debugging or building |
| 1886 | * a user-facing process management UI.</b></p> |
| 1887 | * |
Dianne Hackborn | 4f21c4c | 2009-09-17 10:24:05 -0700 | [diff] [blame] | 1888 | * @param pids The pids of the processes whose memory usage is to be |
| 1889 | * retrieved. |
| 1890 | * @return Returns an array of memory information, one for each |
| 1891 | * requested pid. |
| 1892 | */ |
| 1893 | public Debug.MemoryInfo[] getProcessMemoryInfo(int[] pids) { |
| 1894 | try { |
| 1895 | return ActivityManagerNative.getDefault().getProcessMemoryInfo(pids); |
| 1896 | } catch (RemoteException e) { |
| 1897 | return null; |
| 1898 | } |
| 1899 | } |
| 1900 | |
| 1901 | /** |
Dianne Hackborn | 03abb81 | 2010-01-04 18:43:19 -0800 | [diff] [blame] | 1902 | * @deprecated This is now just a wrapper for |
| 1903 | * {@link #killBackgroundProcesses(String)}; the previous behavior here |
| 1904 | * is no longer available to applications because it allows them to |
| 1905 | * break other applications by removing their alarms, stopping their |
| 1906 | * services, etc. |
| 1907 | */ |
| 1908 | @Deprecated |
| 1909 | public void restartPackage(String packageName) { |
| 1910 | killBackgroundProcesses(packageName); |
| 1911 | } |
| 1912 | |
| 1913 | /** |
| 1914 | * Have the system immediately kill all background processes associated |
| 1915 | * with the given package. This is the same as the kernel killing those |
| 1916 | * processes to reclaim memory; the system will take care of restarting |
| 1917 | * these processes in the future as needed. |
| 1918 | * |
| 1919 | * <p>You must hold the permission |
| 1920 | * {@link android.Manifest.permission#KILL_BACKGROUND_PROCESSES} to be able to |
| 1921 | * call this method. |
| 1922 | * |
| 1923 | * @param packageName The name of the package whose processes are to |
| 1924 | * be killed. |
| 1925 | */ |
| 1926 | public void killBackgroundProcesses(String packageName) { |
| 1927 | try { |
Dianne Hackborn | 1676c85 | 2012-09-10 14:52:30 -0700 | [diff] [blame] | 1928 | ActivityManagerNative.getDefault().killBackgroundProcesses(packageName, |
| 1929 | UserHandle.myUserId()); |
Dianne Hackborn | 03abb81 | 2010-01-04 18:43:19 -0800 | [diff] [blame] | 1930 | } catch (RemoteException e) { |
| 1931 | } |
| 1932 | } |
| 1933 | |
| 1934 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1935 | * Have the system perform a force stop of everything associated with |
| 1936 | * the given application package. All processes that share its uid |
| 1937 | * will be killed, all services it has running stopped, all activities |
| 1938 | * removed, etc. In addition, a {@link Intent#ACTION_PACKAGE_RESTARTED} |
| 1939 | * broadcast will be sent, so that any of its registered alarms can |
| 1940 | * be stopped, notifications removed, etc. |
| 1941 | * |
| 1942 | * <p>You must hold the permission |
Dianne Hackborn | 03abb81 | 2010-01-04 18:43:19 -0800 | [diff] [blame] | 1943 | * {@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] | 1944 | * call this method. |
| 1945 | * |
| 1946 | * @param packageName The name of the package to be stopped. |
Dianne Hackborn | 03abb81 | 2010-01-04 18:43:19 -0800 | [diff] [blame] | 1947 | * |
| 1948 | * @hide This is not available to third party applications due to |
| 1949 | * it allowing them to break other applications by stopping their |
| 1950 | * services, removing their alarms, etc. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1951 | */ |
Dianne Hackborn | 03abb81 | 2010-01-04 18:43:19 -0800 | [diff] [blame] | 1952 | public void forceStopPackage(String packageName) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1953 | try { |
Dianne Hackborn | 1676c85 | 2012-09-10 14:52:30 -0700 | [diff] [blame] | 1954 | ActivityManagerNative.getDefault().forceStopPackage(packageName, |
| 1955 | UserHandle.myUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1956 | } catch (RemoteException e) { |
| 1957 | } |
| 1958 | } |
| 1959 | |
| 1960 | /** |
| 1961 | * Get the device configuration attributes. |
| 1962 | */ |
| 1963 | public ConfigurationInfo getDeviceConfigurationInfo() { |
| 1964 | try { |
| 1965 | return ActivityManagerNative.getDefault().getDeviceConfigurationInfo(); |
| 1966 | } catch (RemoteException e) { |
| 1967 | } |
| 1968 | return null; |
| 1969 | } |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 1970 | |
| 1971 | /** |
| 1972 | * Get the preferred density of icons for the launcher. This is used when |
| 1973 | * custom drawables are created (e.g., for shortcuts). |
| 1974 | * |
| 1975 | * @return density in terms of DPI |
| 1976 | */ |
| 1977 | public int getLauncherLargeIconDensity() { |
| 1978 | final Resources res = mContext.getResources(); |
| 1979 | final int density = res.getDisplayMetrics().densityDpi; |
Dianne Hackborn | d96e3df | 2012-01-25 15:12:23 -0800 | [diff] [blame] | 1980 | final int sw = res.getConfiguration().smallestScreenWidthDp; |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 1981 | |
Dianne Hackborn | d96e3df | 2012-01-25 15:12:23 -0800 | [diff] [blame] | 1982 | if (sw < 600) { |
| 1983 | // Smaller than approx 7" tablets, use the regular icon size. |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 1984 | return density; |
| 1985 | } |
| 1986 | |
| 1987 | switch (density) { |
| 1988 | case DisplayMetrics.DENSITY_LOW: |
| 1989 | return DisplayMetrics.DENSITY_MEDIUM; |
| 1990 | case DisplayMetrics.DENSITY_MEDIUM: |
| 1991 | return DisplayMetrics.DENSITY_HIGH; |
Dianne Hackborn | d0356a1 | 2012-04-26 19:03:12 -0700 | [diff] [blame] | 1992 | case DisplayMetrics.DENSITY_TV: |
| 1993 | return DisplayMetrics.DENSITY_XHIGH; |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 1994 | case DisplayMetrics.DENSITY_HIGH: |
| 1995 | return DisplayMetrics.DENSITY_XHIGH; |
| 1996 | case DisplayMetrics.DENSITY_XHIGH: |
Dianne Hackborn | d96e3df | 2012-01-25 15:12:23 -0800 | [diff] [blame] | 1997 | return DisplayMetrics.DENSITY_XXHIGH; |
| 1998 | case DisplayMetrics.DENSITY_XXHIGH: |
| 1999 | return DisplayMetrics.DENSITY_XHIGH * 2; |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 2000 | default: |
Dianne Hackborn | d96e3df | 2012-01-25 15:12:23 -0800 | [diff] [blame] | 2001 | // The density is some abnormal value. Return some other |
| 2002 | // abnormal value that is a reasonable scaling of it. |
Dianne Hackborn | d0356a1 | 2012-04-26 19:03:12 -0700 | [diff] [blame] | 2003 | return (int)((density*1.5f)+.5f); |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 2004 | } |
| 2005 | } |
| 2006 | |
| 2007 | /** |
| 2008 | * Get the preferred launcher icon size. This is used when custom drawables |
| 2009 | * are created (e.g., for shortcuts). |
| 2010 | * |
| 2011 | * @return dimensions of square icons in terms of pixels |
| 2012 | */ |
| 2013 | public int getLauncherLargeIconSize() { |
| 2014 | final Resources res = mContext.getResources(); |
| 2015 | final int size = res.getDimensionPixelSize(android.R.dimen.app_icon_size); |
Dianne Hackborn | d96e3df | 2012-01-25 15:12:23 -0800 | [diff] [blame] | 2016 | final int sw = res.getConfiguration().smallestScreenWidthDp; |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 2017 | |
Dianne Hackborn | d96e3df | 2012-01-25 15:12:23 -0800 | [diff] [blame] | 2018 | if (sw < 600) { |
| 2019 | // Smaller than approx 7" tablets, use the regular icon size. |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 2020 | return size; |
| 2021 | } |
| 2022 | |
| 2023 | final int density = res.getDisplayMetrics().densityDpi; |
| 2024 | |
| 2025 | switch (density) { |
| 2026 | case DisplayMetrics.DENSITY_LOW: |
| 2027 | return (size * DisplayMetrics.DENSITY_MEDIUM) / DisplayMetrics.DENSITY_LOW; |
| 2028 | case DisplayMetrics.DENSITY_MEDIUM: |
| 2029 | return (size * DisplayMetrics.DENSITY_HIGH) / DisplayMetrics.DENSITY_MEDIUM; |
Dianne Hackborn | d0356a1 | 2012-04-26 19:03:12 -0700 | [diff] [blame] | 2030 | case DisplayMetrics.DENSITY_TV: |
| 2031 | return (size * DisplayMetrics.DENSITY_XHIGH) / DisplayMetrics.DENSITY_HIGH; |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 2032 | case DisplayMetrics.DENSITY_HIGH: |
| 2033 | return (size * DisplayMetrics.DENSITY_XHIGH) / DisplayMetrics.DENSITY_HIGH; |
| 2034 | case DisplayMetrics.DENSITY_XHIGH: |
Dianne Hackborn | d96e3df | 2012-01-25 15:12:23 -0800 | [diff] [blame] | 2035 | return (size * DisplayMetrics.DENSITY_XXHIGH) / DisplayMetrics.DENSITY_XHIGH; |
| 2036 | case DisplayMetrics.DENSITY_XXHIGH: |
| 2037 | return (size * DisplayMetrics.DENSITY_XHIGH*2) / DisplayMetrics.DENSITY_XXHIGH; |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 2038 | default: |
Dianne Hackborn | d96e3df | 2012-01-25 15:12:23 -0800 | [diff] [blame] | 2039 | // The density is some abnormal value. Return some other |
| 2040 | // abnormal value that is a reasonable scaling of it. |
Dianne Hackborn | d0356a1 | 2012-04-26 19:03:12 -0700 | [diff] [blame] | 2041 | return (int)((size*1.5f) + .5f); |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 2042 | } |
| 2043 | } |
| 2044 | |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 2045 | /** |
| 2046 | * Returns "true" if the user interface is currently being messed with |
| 2047 | * by a monkey. |
| 2048 | */ |
| 2049 | public static boolean isUserAMonkey() { |
| 2050 | try { |
| 2051 | return ActivityManagerNative.getDefault().isUserAMonkey(); |
| 2052 | } catch (RemoteException e) { |
| 2053 | } |
| 2054 | return false; |
| 2055 | } |
Brett Chabot | 3b4fcbc | 2011-01-09 13:41:02 -0800 | [diff] [blame] | 2056 | |
| 2057 | /** |
| 2058 | * Returns "true" if device is running in a test harness. |
| 2059 | */ |
| 2060 | public static boolean isRunningInTestHarness() { |
| 2061 | return SystemProperties.getBoolean("ro.test_harness", false); |
| 2062 | } |
Peter Visontay | 8d224ca | 2011-02-18 16:39:19 +0000 | [diff] [blame] | 2063 | |
| 2064 | /** |
| 2065 | * Returns the launch count of each installed package. |
| 2066 | * |
| 2067 | * @hide |
| 2068 | */ |
| 2069 | public Map<String, Integer> getAllPackageLaunchCounts() { |
| 2070 | try { |
| 2071 | IUsageStats usageStatsService = IUsageStats.Stub.asInterface( |
| 2072 | ServiceManager.getService("usagestats")); |
| 2073 | if (usageStatsService == null) { |
| 2074 | return new HashMap<String, Integer>(); |
| 2075 | } |
| 2076 | |
Peter Visontay | bfcda39 | 2011-03-02 18:53:37 +0000 | [diff] [blame] | 2077 | PkgUsageStats[] allPkgUsageStats = usageStatsService.getAllPkgUsageStats(); |
| 2078 | if (allPkgUsageStats == null) { |
| 2079 | return new HashMap<String, Integer>(); |
| 2080 | } |
| 2081 | |
Peter Visontay | 8d224ca | 2011-02-18 16:39:19 +0000 | [diff] [blame] | 2082 | Map<String, Integer> launchCounts = new HashMap<String, Integer>(); |
Peter Visontay | bfcda39 | 2011-03-02 18:53:37 +0000 | [diff] [blame] | 2083 | for (PkgUsageStats pkgUsageStats : allPkgUsageStats) { |
Peter Visontay | 8d224ca | 2011-02-18 16:39:19 +0000 | [diff] [blame] | 2084 | launchCounts.put(pkgUsageStats.packageName, pkgUsageStats.launchCount); |
| 2085 | } |
| 2086 | |
| 2087 | return launchCounts; |
| 2088 | } catch (RemoteException e) { |
| 2089 | Log.w(TAG, "Could not query launch counts", e); |
| 2090 | return new HashMap<String, Integer>(); |
| 2091 | } |
| 2092 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 2093 | |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 2094 | /** @hide */ |
| 2095 | public static int checkComponentPermission(String permission, int uid, |
| 2096 | int owningUid, boolean exported) { |
| 2097 | // Root, system server get to do everything. |
| 2098 | if (uid == 0 || uid == Process.SYSTEM_UID) { |
| 2099 | return PackageManager.PERMISSION_GRANTED; |
| 2100 | } |
| 2101 | // Isolated processes don't get any permissions. |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 2102 | if (UserHandle.isIsolated(uid)) { |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 2103 | return PackageManager.PERMISSION_DENIED; |
| 2104 | } |
| 2105 | // If there is a uid that owns whatever is being accessed, it has |
| 2106 | // blanket access to it regardless of the permissions it requires. |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 2107 | if (owningUid >= 0 && UserHandle.isSameApp(uid, owningUid)) { |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 2108 | return PackageManager.PERMISSION_GRANTED; |
| 2109 | } |
| 2110 | // If the target is not exported, then nobody else can get to it. |
| 2111 | if (!exported) { |
| 2112 | Slog.w(TAG, "Permission denied: checkComponentPermission() owningUid=" + owningUid); |
| 2113 | return PackageManager.PERMISSION_DENIED; |
| 2114 | } |
| 2115 | if (permission == null) { |
| 2116 | return PackageManager.PERMISSION_GRANTED; |
| 2117 | } |
| 2118 | try { |
| 2119 | return AppGlobals.getPackageManager() |
| 2120 | .checkUidPermission(permission, uid); |
| 2121 | } catch (RemoteException e) { |
| 2122 | // Should never happen, but if it does... deny! |
| 2123 | Slog.e(TAG, "PackageManager is dead?!?", e); |
| 2124 | } |
| 2125 | return PackageManager.PERMISSION_DENIED; |
| 2126 | } |
| 2127 | |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 2128 | /** @hide */ |
| 2129 | public static int checkUidPermission(String permission, int uid) { |
| 2130 | try { |
| 2131 | return AppGlobals.getPackageManager() |
| 2132 | .checkUidPermission(permission, uid); |
| 2133 | } catch (RemoteException e) { |
| 2134 | // Should never happen, but if it does... deny! |
| 2135 | Slog.e(TAG, "PackageManager is dead?!?", e); |
| 2136 | } |
| 2137 | return PackageManager.PERMISSION_DENIED; |
| 2138 | } |
| 2139 | |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 2140 | /** |
| 2141 | * @hide |
| 2142 | * Helper for dealing with incoming user arguments to system service calls. |
| 2143 | * Takes care of checking permissions and converting USER_CURRENT to the |
| 2144 | * actual current user. |
| 2145 | * |
| 2146 | * @param callingPid The pid of the incoming call, as per Binder.getCallingPid(). |
| 2147 | * @param callingUid The uid of the incoming call, as per Binder.getCallingUid(). |
| 2148 | * @param userId The user id argument supplied by the caller -- this is the user |
| 2149 | * they want to run as. |
| 2150 | * @param allowAll If true, we will allow USER_ALL. This means you must be prepared |
| 2151 | * to get a USER_ALL returned and deal with it correctly. If false, |
| 2152 | * an exception will be thrown if USER_ALL is supplied. |
| 2153 | * @param requireFull If true, the caller must hold |
| 2154 | * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} to be able to run as a |
| 2155 | * different user than their current process; otherwise they must hold |
| 2156 | * {@link android.Manifest.permission#INTERACT_ACROSS_USERS}. |
| 2157 | * @param name Optional textual name of the incoming call; only for generating error messages. |
| 2158 | * @param callerPackage Optional package name of caller; only for error messages. |
| 2159 | * |
| 2160 | * @return Returns the user ID that the call should run as. Will always be a concrete |
| 2161 | * user number, unless <var>allowAll</var> is true in which case it could also be |
| 2162 | * USER_ALL. |
| 2163 | */ |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 2164 | public static int handleIncomingUser(int callingPid, int callingUid, int userId, |
| 2165 | boolean allowAll, boolean requireFull, String name, String callerPackage) { |
| 2166 | if (UserHandle.getUserId(callingUid) == userId) { |
| 2167 | return userId; |
| 2168 | } |
| 2169 | try { |
| 2170 | return ActivityManagerNative.getDefault().handleIncomingUser(callingPid, |
| 2171 | callingUid, userId, allowAll, requireFull, name, callerPackage); |
| 2172 | } catch (RemoteException e) { |
| 2173 | throw new SecurityException("Failed calling activity manager", e); |
| 2174 | } |
| 2175 | } |
| 2176 | |
| 2177 | /** @hide */ |
| 2178 | public static int getCurrentUser() { |
| 2179 | UserInfo ui; |
| 2180 | try { |
| 2181 | ui = ActivityManagerNative.getDefault().getCurrentUser(); |
| 2182 | return ui != null ? ui.id : 0; |
| 2183 | } catch (RemoteException e) { |
| 2184 | return 0; |
| 2185 | } |
| 2186 | } |
| 2187 | |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 2188 | /** |
Mark Brophy | 9fc0330 | 2011-07-01 16:56:24 +0100 | [diff] [blame] | 2189 | * Returns the usage statistics of each installed package. |
| 2190 | * |
| 2191 | * @hide |
| 2192 | */ |
| 2193 | public PkgUsageStats[] getAllPackageUsageStats() { |
| 2194 | try { |
| 2195 | IUsageStats usageStatsService = IUsageStats.Stub.asInterface( |
| 2196 | ServiceManager.getService("usagestats")); |
| 2197 | if (usageStatsService != null) { |
| 2198 | return usageStatsService.getAllPkgUsageStats(); |
| 2199 | } |
| 2200 | } catch (RemoteException e) { |
| 2201 | Log.w(TAG, "Could not query usage stats", e); |
| 2202 | } |
| 2203 | return new PkgUsageStats[0]; |
| 2204 | } |
| 2205 | |
| 2206 | /** |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 2207 | * @param userid the user's id. Zero indicates the default user |
| 2208 | * @hide |
| 2209 | */ |
| 2210 | public boolean switchUser(int userid) { |
| 2211 | try { |
| 2212 | return ActivityManagerNative.getDefault().switchUser(userid); |
| 2213 | } catch (RemoteException e) { |
| 2214 | return false; |
| 2215 | } |
| 2216 | } |
Dianne Hackborn | 5e03e2c | 2012-09-06 14:21:19 -0700 | [diff] [blame] | 2217 | |
| 2218 | /** |
| 2219 | * Return whether the given user is actively running. This means that |
| 2220 | * the user is in the "started" state, not "stopped" -- it is currently |
| 2221 | * allowed to run code through scheduled alarms, receiving broadcasts, |
| 2222 | * etc. A started user may be either the current foreground user or a |
| 2223 | * background user; the result here does not distinguish between the two. |
| 2224 | * @param userid the user's id. Zero indicates the default user. |
| 2225 | * @hide |
| 2226 | */ |
| 2227 | public boolean isUserRunning(int userid) { |
| 2228 | try { |
Dianne Hackborn | a8a9bd6 | 2012-10-09 15:36:59 -0700 | [diff] [blame] | 2229 | return ActivityManagerNative.getDefault().isUserRunning(userid, false); |
Dianne Hackborn | 5e03e2c | 2012-09-06 14:21:19 -0700 | [diff] [blame] | 2230 | } catch (RemoteException e) { |
| 2231 | return false; |
| 2232 | } |
| 2233 | } |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 2234 | |
| 2235 | /** |
| 2236 | * Perform a system dump of various state associated with the given application |
| 2237 | * package name. This call blocks while the dump is being performed, so should |
| 2238 | * not be done on a UI thread. The data will be written to the given file |
| 2239 | * descriptor as text. An application must hold the |
| 2240 | * {@link android.Manifest.permission#DUMP} permission to make this call. |
| 2241 | * @param fd The file descriptor that the dump should be written to. |
| 2242 | * @param packageName The name of the package that is to be dumped. |
| 2243 | */ |
| 2244 | public void dumpPackageState(FileDescriptor fd, String packageName) { |
| 2245 | dumpPackageStateStatic(fd, packageName); |
| 2246 | } |
| 2247 | |
| 2248 | /** |
| 2249 | * @hide |
| 2250 | */ |
| 2251 | public static void dumpPackageStateStatic(FileDescriptor fd, String packageName) { |
| 2252 | FileOutputStream fout = new FileOutputStream(fd); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 2253 | PrintWriter pw = new FastPrintWriter(fout); |
| 2254 | dumpService(pw, fd, Context.ACTIVITY_SERVICE, new String[] { "package", packageName }); |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 2255 | pw.println(); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 2256 | dumpService(pw, fd, "procstats", new String[] { packageName }); |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 2257 | pw.println(); |
Dianne Hackborn | 904a857 | 2013-06-28 18:12:31 -0700 | [diff] [blame] | 2258 | dumpService(pw, fd, "usagestats", new String[] { "--packages", packageName }); |
| 2259 | pw.println(); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 2260 | dumpService(pw, fd, "package", new String[] { packageName }); |
| 2261 | pw.println(); |
| 2262 | dumpService(pw, fd, BatteryStats.SERVICE_NAME, new String[] { packageName }); |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 2263 | pw.flush(); |
| 2264 | } |
| 2265 | |
| 2266 | private static void dumpService(PrintWriter pw, FileDescriptor fd, String name, String[] args) { |
| 2267 | pw.print("DUMP OF SERVICE "); pw.print(name); pw.println(":"); |
| 2268 | IBinder service = ServiceManager.checkService(name); |
| 2269 | if (service == null) { |
| 2270 | pw.println(" (Service not found)"); |
| 2271 | return; |
| 2272 | } |
| 2273 | TransferPipe tp = null; |
| 2274 | try { |
| 2275 | pw.flush(); |
| 2276 | tp = new TransferPipe(); |
| 2277 | tp.setBufferPrefix(" "); |
| 2278 | service.dump(tp.getWriteFd().getFileDescriptor(), args); |
| 2279 | tp.go(fd); |
| 2280 | } catch (Throwable e) { |
| 2281 | if (tp != null) { |
| 2282 | tp.kill(); |
| 2283 | } |
| 2284 | pw.println("Failure dumping service:"); |
| 2285 | e.printStackTrace(pw); |
| 2286 | } |
| 2287 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2288 | } |