blob: f48b8edf64f8bc548341b89b6faed2a017f5d6ab [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
17package android.app;
18
Amith Yamasani4b2e9342011-03-31 12:38:53 -070019import com.android.internal.app.IUsageStats;
20import com.android.internal.os.PkgUsageStats;
21
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022import android.content.ComponentName;
23import android.content.Context;
24import android.content.Intent;
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -070025import android.content.pm.ApplicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import android.content.pm.ConfigurationInfo;
27import android.content.pm.IPackageDataObserver;
Kenny Root5ef44b72011-01-26 17:22:20 -080028import android.content.res.Configuration;
29import android.content.res.Resources;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030import android.graphics.Bitmap;
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -070031import android.os.Debug;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032import android.os.Handler;
33import android.os.Parcel;
34import android.os.Parcelable;
Amith Yamasani4b2e9342011-03-31 12:38:53 -070035import android.os.RemoteException;
Peter Visontay8d224ca2011-02-18 16:39:19 +000036import android.os.ServiceManager;
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -070037import android.os.SystemProperties;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038import android.text.TextUtils;
Kenny Root5ef44b72011-01-26 17:22:20 -080039import android.util.DisplayMetrics;
Peter Visontay8d224ca2011-02-18 16:39:19 +000040import android.util.Log;
Kenny Root5ef44b72011-01-26 17:22:20 -080041
Dianne Hackbornf26fd992011-04-08 18:14:09 -070042import java.util.ArrayList;
Peter Visontay8d224ca2011-02-18 16:39:19 +000043import java.util.HashMap;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044import java.util.List;
Peter Visontay8d224ca2011-02-18 16:39:19 +000045import java.util.Map;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046
47/**
48 * Interact with the overall activities running in the system.
49 */
50public class ActivityManager {
51 private static String TAG = "ActivityManager";
Joe Onorato43a17652011-04-06 19:22:23 -070052 private static boolean localLOGV = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053
54 private final Context mContext;
55 private final Handler mHandler;
56
57 /*package*/ ActivityManager(Context context, Handler handler) {
58 mContext = context;
59 mHandler = handler;
60 }
61
62 /**
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -070063 * Screen compatibility mode: the application most always run in
64 * compatibility mode.
65 * @hide
66 */
67 public static final int COMPAT_MODE_ALWAYS = -1;
68
69 /**
70 * Screen compatibility mode: the application can never run in
71 * compatibility mode.
72 * @hide
73 */
74 public static final int COMPAT_MODE_NEVER = -2;
75
76 /**
77 * Screen compatibility mode: unknown.
78 * @hide
79 */
80 public static final int COMPAT_MODE_UNKNOWN = -3;
81
82 /**
83 * Screen compatibility mode: the application currently has compatibility
84 * mode disabled.
85 * @hide
86 */
87 public static final int COMPAT_MODE_DISABLED = 0;
88
89 /**
90 * Screen compatibility mode: the application currently has compatibility
91 * mode enabled.
92 * @hide
93 */
94 public static final int COMPAT_MODE_ENABLED = 1;
95
96 /**
97 * Screen compatibility mode: request to toggle the application's
98 * compatibility mode.
99 * @hide
100 */
101 public static final int COMPAT_MODE_TOGGLE = 2;
102
103 /** @hide */
104 public int getFrontActivityScreenCompatMode() {
105 try {
106 return ActivityManagerNative.getDefault().getFrontActivityScreenCompatMode();
107 } catch (RemoteException e) {
108 // System dead, we will be dead too soon!
109 return 0;
110 }
111 }
112
113 public void setFrontActivityScreenCompatMode(int mode) {
114 try {
115 ActivityManagerNative.getDefault().setFrontActivityScreenCompatMode(mode);
116 } catch (RemoteException e) {
117 // System dead, we will be dead too soon!
118 }
119 }
120
121 public int getPackageScreenCompatMode(String packageName) {
122 try {
123 return ActivityManagerNative.getDefault().getPackageScreenCompatMode(packageName);
124 } catch (RemoteException e) {
125 // System dead, we will be dead too soon!
126 return 0;
127 }
128 }
129
130 public void setPackageScreenCompatMode(String packageName, int mode) {
131 try {
132 ActivityManagerNative.getDefault().setPackageScreenCompatMode(packageName, mode);
133 } catch (RemoteException e) {
134 // System dead, we will be dead too soon!
135 }
136 }
137
138 /**
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700139 * Return the approximate per-application memory class of the current
140 * device. This gives you an idea of how hard a memory limit you should
141 * impose on your application to let the overall system work best. The
142 * returned value is in megabytes; the baseline Android memory class is
143 * 16 (which happens to be the Java heap limit of those devices); some
144 * device with more memory may return 24 or even higher numbers.
145 */
146 public int getMemoryClass() {
147 return staticGetMemoryClass();
148 }
149
150 /** @hide */
151 static public int staticGetMemoryClass() {
152 // Really brain dead right now -- just take this from the configured
153 // vm heap size, and assume it is in megabytes and thus ends with "m".
Dianne Hackborn7ad33c82011-03-08 15:53:25 -0800154 String vmHeapSize = SystemProperties.get("dalvik.vm.heapgrowthlimit", "");
Dianne Hackbornde398512011-01-18 18:45:21 -0800155 if (vmHeapSize != null && !"".equals(vmHeapSize)) {
156 return Integer.parseInt(vmHeapSize.substring(0, vmHeapSize.length()-1));
157 }
158 return staticGetLargeMemoryClass();
Dianne Hackborn4e24aac2010-12-23 11:43:46 -0800159 }
160
161 /**
162 * Return the approximate per-application memory class of the current
163 * device when an application is running with a large heap. This is the
164 * space available for memory-intensive applications; most applications
165 * should not need this amount of memory, and should instead stay with the
166 * {@link #getMemoryClass()} limit. The returned value is in megabytes.
167 * This may be the same size as {@link #getMemoryClass()} on memory
168 * constrained devices, or it may be significantly larger on devices with
169 * a large amount of available RAM.
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800170 *
171 * <p>The is the size of the application's Dalvik heap if it has
172 * specified <code>android:largeHeap="true"</code> in its manifest.
Dianne Hackborn4e24aac2010-12-23 11:43:46 -0800173 */
174 public int getLargeMemoryClass() {
175 return staticGetLargeMemoryClass();
176 }
177
178 /** @hide */
179 static public int staticGetLargeMemoryClass() {
180 // Really brain dead right now -- just take this from the configured
181 // vm heap size, and assume it is in megabytes and thus ends with "m".
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700182 String vmHeapSize = SystemProperties.get("dalvik.vm.heapsize", "16m");
183 return Integer.parseInt(vmHeapSize.substring(0, vmHeapSize.length()-1));
184 }
185
186 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800187 * Information you can retrieve about tasks that the user has most recently
188 * started or visited.
189 */
190 public static class RecentTaskInfo implements Parcelable {
191 /**
192 * If this task is currently running, this is the identifier for it.
193 * If it is not running, this will be -1.
194 */
195 public int id;
196
197 /**
Dianne Hackbornd94df452011-02-16 18:53:31 -0800198 * The true identifier of this task, valid even if it is not running.
199 */
200 public int persistentId;
201
202 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800203 * The original Intent used to launch the task. You can use this
204 * Intent to re-launch the task (if it is no longer running) or bring
205 * the current task to the front.
206 */
207 public Intent baseIntent;
208
209 /**
210 * If this task was started from an alias, this is the actual
211 * activity component that was initially started; the component of
212 * the baseIntent in this case is the name of the actual activity
213 * implementation that the alias referred to. Otherwise, this is null.
214 */
215 public ComponentName origActivity;
Dianne Hackbornd2835932010-12-13 16:28:46 -0800216
217 /**
Dianne Hackbornd2835932010-12-13 16:28:46 -0800218 * Description of the task's last state.
219 */
220 public CharSequence description;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221
222 public RecentTaskInfo() {
223 }
224
225 public int describeContents() {
226 return 0;
227 }
228
229 public void writeToParcel(Parcel dest, int flags) {
230 dest.writeInt(id);
Dianne Hackbornd94df452011-02-16 18:53:31 -0800231 dest.writeInt(persistentId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800232 if (baseIntent != null) {
233 dest.writeInt(1);
234 baseIntent.writeToParcel(dest, 0);
235 } else {
236 dest.writeInt(0);
237 }
238 ComponentName.writeToParcel(origActivity, dest);
Dianne Hackbornd2835932010-12-13 16:28:46 -0800239 TextUtils.writeToParcel(description, dest,
240 Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800241 }
242
243 public void readFromParcel(Parcel source) {
244 id = source.readInt();
Dianne Hackbornd94df452011-02-16 18:53:31 -0800245 persistentId = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800246 if (source.readInt() != 0) {
247 baseIntent = Intent.CREATOR.createFromParcel(source);
248 } else {
249 baseIntent = null;
250 }
251 origActivity = ComponentName.readFromParcel(source);
Dianne Hackbornd2835932010-12-13 16:28:46 -0800252 description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800253 }
254
255 public static final Creator<RecentTaskInfo> CREATOR
256 = new Creator<RecentTaskInfo>() {
257 public RecentTaskInfo createFromParcel(Parcel source) {
258 return new RecentTaskInfo(source);
259 }
260 public RecentTaskInfo[] newArray(int size) {
261 return new RecentTaskInfo[size];
262 }
263 };
264
265 private RecentTaskInfo(Parcel source) {
266 readFromParcel(source);
267 }
268 }
269
270 /**
271 * Flag for use with {@link #getRecentTasks}: return all tasks, even those
272 * that have set their
273 * {@link android.content.Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} flag.
274 */
275 public static final int RECENT_WITH_EXCLUDED = 0x0001;
276
277 /**
Dianne Hackbornd2835932010-12-13 16:28:46 -0800278 * Provides a list that does not contain any
Dianne Hackborn53d9264d2010-04-13 12:49:14 -0700279 * recent tasks that currently are not available to the user.
280 */
281 public static final int RECENT_IGNORE_UNAVAILABLE = 0x0002;
Dianne Hackbornd2835932010-12-13 16:28:46 -0800282
283 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800284 * Return a list of the tasks that the user has recently launched, with
285 * the most recent being first and older ones after in order.
286 *
287 * @param maxNum The maximum number of entries to return in the list. The
288 * actual number returned may be smaller, depending on how many tasks the
289 * user has started and the maximum number the system can remember.
Dianne Hackbornd2835932010-12-13 16:28:46 -0800290 * @param flags Information about what to return. May be any combination
Dianne Hackborn805fd7e2011-01-16 18:30:29 -0800291 * of {@link #RECENT_WITH_EXCLUDED} and {@link #RECENT_IGNORE_UNAVAILABLE}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800292 *
293 * @return Returns a list of RecentTaskInfo records describing each of
294 * the recent tasks.
295 *
296 * @throws SecurityException Throws SecurityException if the caller does
297 * not hold the {@link android.Manifest.permission#GET_TASKS} permission.
298 */
299 public List<RecentTaskInfo> getRecentTasks(int maxNum, int flags)
300 throws SecurityException {
301 try {
302 return ActivityManagerNative.getDefault().getRecentTasks(maxNum,
303 flags);
304 } catch (RemoteException e) {
305 // System dead, we will be dead too soon!
306 return null;
307 }
308 }
309
310 /**
311 * Information you can retrieve about a particular task that is currently
312 * "running" in the system. Note that a running task does not mean the
Dianne Hackborn0c5001d2011-04-12 18:16:08 -0700313 * given task actually has a process it is actively running in; it simply
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800314 * means that the user has gone to it and never closed it, but currently
315 * the system may have killed its process and is only holding on to its
316 * last state in order to restart it when the user returns.
317 */
318 public static class RunningTaskInfo implements Parcelable {
319 /**
320 * A unique identifier for this task.
321 */
322 public int id;
323
324 /**
325 * The component launched as the first activity in the task. This can
326 * be considered the "application" of this task.
327 */
328 public ComponentName baseActivity;
329
330 /**
331 * The activity component at the top of the history stack of the task.
332 * This is what the user is currently doing.
333 */
334 public ComponentName topActivity;
335
336 /**
Dianne Hackborn805fd7e2011-01-16 18:30:29 -0800337 * Thumbnail representation of the task's current state. Currently
338 * always null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800339 */
340 public Bitmap thumbnail;
341
342 /**
343 * Description of the task's current state.
344 */
345 public CharSequence description;
346
347 /**
348 * Number of activities in this task.
349 */
350 public int numActivities;
351
352 /**
353 * Number of activities that are currently running (not stopped
354 * and persisted) in this task.
355 */
356 public int numRunning;
357
358 public RunningTaskInfo() {
359 }
360
361 public int describeContents() {
362 return 0;
363 }
364
365 public void writeToParcel(Parcel dest, int flags) {
366 dest.writeInt(id);
367 ComponentName.writeToParcel(baseActivity, dest);
368 ComponentName.writeToParcel(topActivity, dest);
369 if (thumbnail != null) {
370 dest.writeInt(1);
371 thumbnail.writeToParcel(dest, 0);
372 } else {
373 dest.writeInt(0);
374 }
375 TextUtils.writeToParcel(description, dest,
376 Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
377 dest.writeInt(numActivities);
378 dest.writeInt(numRunning);
379 }
380
381 public void readFromParcel(Parcel source) {
382 id = source.readInt();
383 baseActivity = ComponentName.readFromParcel(source);
384 topActivity = ComponentName.readFromParcel(source);
385 if (source.readInt() != 0) {
386 thumbnail = Bitmap.CREATOR.createFromParcel(source);
387 } else {
388 thumbnail = null;
389 }
390 description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
391 numActivities = source.readInt();
392 numRunning = source.readInt();
393 }
394
395 public static final Creator<RunningTaskInfo> CREATOR = new Creator<RunningTaskInfo>() {
396 public RunningTaskInfo createFromParcel(Parcel source) {
397 return new RunningTaskInfo(source);
398 }
399 public RunningTaskInfo[] newArray(int size) {
400 return new RunningTaskInfo[size];
401 }
402 };
403
404 private RunningTaskInfo(Parcel source) {
405 readFromParcel(source);
406 }
407 }
Dianne Hackbornd2835932010-12-13 16:28:46 -0800408
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800409 /**
410 * Return a list of the tasks that are currently running, with
411 * the most recent being first and older ones after in order. Note that
412 * "running" does not mean any of the task's code is currently loaded or
413 * activity -- the task may have been frozen by the system, so that it
414 * can be restarted in its previous state when next brought to the
415 * foreground.
416 *
417 * @param maxNum The maximum number of entries to return in the list. The
418 * actual number returned may be smaller, depending on how many tasks the
419 * user has started.
Jim Miller0b2a6d02010-07-13 18:01:29 -0700420 *
421 * @param flags Optional flags
422 * @param receiver Optional receiver for delayed thumbnails
423 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800424 * @return Returns a list of RunningTaskInfo records describing each of
425 * the running tasks.
426 *
Jim Miller0b2a6d02010-07-13 18:01:29 -0700427 * Some thumbnails may not be available at the time of this call. The optional
428 * receiver may be used to receive those thumbnails.
429 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800430 * @throws SecurityException Throws SecurityException if the caller does
431 * not hold the {@link android.Manifest.permission#GET_TASKS} permission.
Jim Miller0b2a6d02010-07-13 18:01:29 -0700432 *
433 * @hide
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800434 */
Jim Miller0b2a6d02010-07-13 18:01:29 -0700435 public List<RunningTaskInfo> getRunningTasks(int maxNum, int flags, IThumbnailReceiver receiver)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800436 throws SecurityException {
437 try {
Jim Miller0b2a6d02010-07-13 18:01:29 -0700438 return ActivityManagerNative.getDefault().getTasks(maxNum, flags, receiver);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800439 } catch (RemoteException e) {
440 // System dead, we will be dead too soon!
441 return null;
442 }
443 }
Jim Miller0b2a6d02010-07-13 18:01:29 -0700444
445 /**
446 * Return a list of the tasks that are currently running, with
447 * the most recent being first and older ones after in order. Note that
448 * "running" does not mean any of the task's code is currently loaded or
449 * activity -- the task may have been frozen by the system, so that it
450 * can be restarted in its previous state when next brought to the
451 * foreground.
452 *
453 * @param maxNum The maximum number of entries to return in the list. The
454 * actual number returned may be smaller, depending on how many tasks the
455 * user has started.
456 *
457 * @return Returns a list of RunningTaskInfo records describing each of
458 * the running tasks.
459 *
460 * @throws SecurityException Throws SecurityException if the caller does
461 * not hold the {@link android.Manifest.permission#GET_TASKS} permission.
462 */
463 public List<RunningTaskInfo> getRunningTasks(int maxNum)
464 throws SecurityException {
465 return getRunningTasks(maxNum, 0, null);
466 }
467
Dianne Hackborn0c5001d2011-04-12 18:16:08 -0700468 /**
469 * Remove some end of a task's activity stack that is not part of
470 * the main application. The selected activities will be finished, so
471 * they are no longer part of the main task.
472 *
473 * @param taskId The identifier of the task.
474 * @param subTaskIndex The number of the sub-task; this corresponds
475 * to the index of the thumbnail returned by {@link #getTaskThumbnails(int)}.
476 * @return Returns true if the sub-task was found and was removed.
477 *
478 * @hide
479 */
480 public boolean removeSubTask(int taskId, int subTaskIndex)
481 throws SecurityException {
482 try {
483 return ActivityManagerNative.getDefault().removeSubTask(taskId, subTaskIndex);
484 } catch (RemoteException e) {
485 // System dead, we will be dead too soon!
486 return false;
487 }
488 }
489
490 /**
491 * If set, the process of the root activity of the task will be killed
492 * as part of removing the task.
493 * @hide
494 */
495 public static final int REMOVE_TASK_KILL_PROCESS = 0x0001;
496
497 /**
498 * Completely remove the given task.
499 *
500 * @param taskId Identifier of the task to be removed.
501 * @param flags Additional operational flags. May be 0 or
502 * {@link #REMOVE_TASK_KILL_PROCESS}.
503 * @return Returns true if the given task was found and removed.
504 *
505 * @hide
506 */
507 public boolean removeTask(int taskId, int flags)
508 throws SecurityException {
509 try {
510 return ActivityManagerNative.getDefault().removeTask(taskId, flags);
511 } catch (RemoteException e) {
512 // System dead, we will be dead too soon!
513 return false;
514 }
515 }
516
Dianne Hackbornd94df452011-02-16 18:53:31 -0800517 /** @hide */
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700518 public static class TaskThumbnails implements Parcelable {
519 public Bitmap mainThumbnail;
520
521 public int numSubThumbbails;
522
523 /** @hide */
524 public IThumbnailRetriever retriever;
525
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700526 public TaskThumbnails() {
527 }
528
529 public Bitmap getSubThumbnail(int index) {
530 try {
531 return retriever.getThumbnail(index);
532 } catch (RemoteException e) {
533 return null;
534 }
535 }
536
537 public int describeContents() {
538 return 0;
539 }
540
541 public void writeToParcel(Parcel dest, int flags) {
542 if (mainThumbnail != null) {
543 dest.writeInt(1);
544 mainThumbnail.writeToParcel(dest, 0);
545 } else {
546 dest.writeInt(0);
547 }
548 dest.writeInt(numSubThumbbails);
549 dest.writeStrongInterface(retriever);
550 }
551
552 public void readFromParcel(Parcel source) {
553 if (source.readInt() != 0) {
554 mainThumbnail = Bitmap.CREATOR.createFromParcel(source);
555 } else {
556 mainThumbnail = null;
557 }
558 numSubThumbbails = source.readInt();
559 retriever = IThumbnailRetriever.Stub.asInterface(source.readStrongBinder());
560 }
561
562 public static final Creator<TaskThumbnails> CREATOR = new Creator<TaskThumbnails>() {
563 public TaskThumbnails createFromParcel(Parcel source) {
564 return new TaskThumbnails(source);
565 }
566 public TaskThumbnails[] newArray(int size) {
567 return new TaskThumbnails[size];
568 }
569 };
570
571 private TaskThumbnails(Parcel source) {
572 readFromParcel(source);
573 }
574 }
575
576 /** @hide */
577 public TaskThumbnails getTaskThumbnails(int id) throws SecurityException {
Dianne Hackbornd94df452011-02-16 18:53:31 -0800578 try {
Dianne Hackbornf26fd992011-04-08 18:14:09 -0700579 return ActivityManagerNative.getDefault().getTaskThumbnails(id);
Dianne Hackbornd94df452011-02-16 18:53:31 -0800580 } catch (RemoteException e) {
581 // System dead, we will be dead too soon!
582 return null;
583 }
584 }
585
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800586 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800587 * Flag for {@link #moveTaskToFront(int, int)}: also move the "home"
588 * activity along with the task, so it is positioned immediately behind
589 * the task.
590 */
591 public static final int MOVE_TASK_WITH_HOME = 0x00000001;
592
593 /**
Dianne Hackbornd94df452011-02-16 18:53:31 -0800594 * Flag for {@link #moveTaskToFront(int, int)}: don't count this as a
595 * user-instigated action, so the current activity will not receive a
596 * hint that the user is leaving.
597 */
598 public static final int MOVE_TASK_NO_USER_ACTION = 0x00000002;
599
600 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800601 * Ask that the task associated with a given task ID be moved to the
602 * front of the stack, so it is now visible to the user. Requires that
603 * the caller hold permission {@link android.Manifest.permission#REORDER_TASKS}
604 * or a SecurityException will be thrown.
605 *
606 * @param taskId The identifier of the task to be moved, as found in
607 * {@link RunningTaskInfo} or {@link RecentTaskInfo}.
608 * @param flags Additional operational flags, 0 or more of
609 * {@link #MOVE_TASK_WITH_HOME}.
610 */
611 public void moveTaskToFront(int taskId, int flags) {
612 try {
613 ActivityManagerNative.getDefault().moveTaskToFront(taskId, flags);
614 } catch (RemoteException e) {
615 // System dead, we will be dead too soon!
616 }
617 }
618
619 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800620 * Information you can retrieve about a particular Service that is
621 * currently running in the system.
622 */
623 public static class RunningServiceInfo implements Parcelable {
624 /**
625 * The service component.
626 */
627 public ComponentName service;
628
629 /**
630 * If non-zero, this is the process the service is running in.
631 */
632 public int pid;
633
634 /**
Dianne Hackborn3025ef32009-08-31 21:31:47 -0700635 * The UID that owns this service.
636 */
637 public int uid;
638
639 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800640 * The name of the process this service runs in.
641 */
642 public String process;
643
644 /**
645 * Set to true if the service has asked to run as a foreground process.
646 */
647 public boolean foreground;
648
649 /**
Dianne Hackborn3025ef32009-08-31 21:31:47 -0700650 * The time when the service was first made active, either by someone
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700651 * starting or binding to it. This
652 * is in units of {@link android.os.SystemClock#elapsedRealtime()}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800653 */
654 public long activeSince;
655
656 /**
657 * Set to true if this service has been explicitly started.
658 */
659 public boolean started;
660
661 /**
662 * Number of clients connected to the service.
663 */
664 public int clientCount;
665
666 /**
667 * Number of times the service's process has crashed while the service
668 * is running.
669 */
670 public int crashCount;
671
672 /**
673 * The time when there was last activity in the service (either
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700674 * explicit requests to start it or clients binding to it). This
675 * is in units of {@link android.os.SystemClock#uptimeMillis()}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800676 */
677 public long lastActivityTime;
678
679 /**
680 * If non-zero, this service is not currently running, but scheduled to
681 * restart at the given time.
682 */
683 public long restarting;
684
Dianne Hackborn3025ef32009-08-31 21:31:47 -0700685 /**
686 * Bit for {@link #flags}: set if this service has been
687 * explicitly started.
688 */
689 public static final int FLAG_STARTED = 1<<0;
690
691 /**
692 * Bit for {@link #flags}: set if the service has asked to
693 * run as a foreground process.
694 */
695 public static final int FLAG_FOREGROUND = 1<<1;
696
697 /**
698 * Bit for {@link #flags): set if the service is running in a
699 * core system process.
700 */
701 public static final int FLAG_SYSTEM_PROCESS = 1<<2;
702
703 /**
704 * Bit for {@link #flags): set if the service is running in a
705 * persistent process.
706 */
707 public static final int FLAG_PERSISTENT_PROCESS = 1<<3;
708
709 /**
710 * Running flags.
711 */
712 public int flags;
713
Dianne Hackborndd9b82c2009-09-03 00:18:47 -0700714 /**
715 * For special services that are bound to by system code, this is
716 * the package that holds the binding.
717 */
718 public String clientPackage;
719
720 /**
721 * For special services that are bound to by system code, this is
722 * a string resource providing a user-visible label for who the
723 * client is.
724 */
725 public int clientLabel;
726
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800727 public RunningServiceInfo() {
728 }
729
730 public int describeContents() {
731 return 0;
732 }
733
734 public void writeToParcel(Parcel dest, int flags) {
735 ComponentName.writeToParcel(service, dest);
736 dest.writeInt(pid);
Dianne Hackborn3025ef32009-08-31 21:31:47 -0700737 dest.writeInt(uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800738 dest.writeString(process);
739 dest.writeInt(foreground ? 1 : 0);
740 dest.writeLong(activeSince);
741 dest.writeInt(started ? 1 : 0);
742 dest.writeInt(clientCount);
743 dest.writeInt(crashCount);
744 dest.writeLong(lastActivityTime);
745 dest.writeLong(restarting);
Dianne Hackborn3025ef32009-08-31 21:31:47 -0700746 dest.writeInt(this.flags);
Dianne Hackborndd9b82c2009-09-03 00:18:47 -0700747 dest.writeString(clientPackage);
748 dest.writeInt(clientLabel);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800749 }
750
751 public void readFromParcel(Parcel source) {
752 service = ComponentName.readFromParcel(source);
753 pid = source.readInt();
Dianne Hackborn3025ef32009-08-31 21:31:47 -0700754 uid = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800755 process = source.readString();
756 foreground = source.readInt() != 0;
757 activeSince = source.readLong();
758 started = source.readInt() != 0;
759 clientCount = source.readInt();
760 crashCount = source.readInt();
761 lastActivityTime = source.readLong();
762 restarting = source.readLong();
Dianne Hackborn3025ef32009-08-31 21:31:47 -0700763 flags = source.readInt();
Dianne Hackborndd9b82c2009-09-03 00:18:47 -0700764 clientPackage = source.readString();
765 clientLabel = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800766 }
767
768 public static final Creator<RunningServiceInfo> CREATOR = new Creator<RunningServiceInfo>() {
769 public RunningServiceInfo createFromParcel(Parcel source) {
770 return new RunningServiceInfo(source);
771 }
772 public RunningServiceInfo[] newArray(int size) {
773 return new RunningServiceInfo[size];
774 }
775 };
776
777 private RunningServiceInfo(Parcel source) {
778 readFromParcel(source);
779 }
780 }
781
782 /**
783 * Return a list of the services that are currently running.
784 *
785 * @param maxNum The maximum number of entries to return in the list. The
786 * actual number returned may be smaller, depending on how many services
787 * are running.
788 *
789 * @return Returns a list of RunningServiceInfo records describing each of
790 * the running tasks.
791 */
792 public List<RunningServiceInfo> getRunningServices(int maxNum)
793 throws SecurityException {
794 try {
Amith Yamasani4b2e9342011-03-31 12:38:53 -0700795 return ActivityManagerNative.getDefault()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800796 .getServices(maxNum, 0);
797 } catch (RemoteException e) {
798 // System dead, we will be dead too soon!
799 return null;
800 }
801 }
802
803 /**
Dianne Hackborndd9b82c2009-09-03 00:18:47 -0700804 * Returns a PendingIntent you can start to show a control panel for the
805 * given running service. If the service does not have a control panel,
806 * null is returned.
807 */
808 public PendingIntent getRunningServiceControlPanel(ComponentName service)
809 throws SecurityException {
810 try {
811 return ActivityManagerNative.getDefault()
812 .getRunningServiceControlPanel(service);
813 } catch (RemoteException e) {
814 // System dead, we will be dead too soon!
815 return null;
816 }
817 }
818
819 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800820 * Information you can retrieve about the available memory through
821 * {@link ActivityManager#getMemoryInfo}.
822 */
823 public static class MemoryInfo implements Parcelable {
824 /**
825 * The total available memory on the system. This number should not
826 * be considered absolute: due to the nature of the kernel, a significant
827 * portion of this memory is actually in use and needed for the overall
828 * system to run well.
829 */
830 public long availMem;
831
832 /**
833 * The threshold of {@link #availMem} at which we consider memory to be
834 * low and start killing background services and other non-extraneous
835 * processes.
836 */
837 public long threshold;
838
839 /**
840 * Set to true if the system considers itself to currently be in a low
841 * memory situation.
842 */
843 public boolean lowMemory;
844
845 public MemoryInfo() {
846 }
847
848 public int describeContents() {
849 return 0;
850 }
851
852 public void writeToParcel(Parcel dest, int flags) {
853 dest.writeLong(availMem);
854 dest.writeLong(threshold);
855 dest.writeInt(lowMemory ? 1 : 0);
856 }
857
858 public void readFromParcel(Parcel source) {
859 availMem = source.readLong();
860 threshold = source.readLong();
861 lowMemory = source.readInt() != 0;
862 }
863
864 public static final Creator<MemoryInfo> CREATOR
865 = new Creator<MemoryInfo>() {
866 public MemoryInfo createFromParcel(Parcel source) {
867 return new MemoryInfo(source);
868 }
869 public MemoryInfo[] newArray(int size) {
870 return new MemoryInfo[size];
871 }
872 };
873
874 private MemoryInfo(Parcel source) {
875 readFromParcel(source);
876 }
877 }
878
879 public void getMemoryInfo(MemoryInfo outInfo) {
880 try {
881 ActivityManagerNative.getDefault().getMemoryInfo(outInfo);
882 } catch (RemoteException e) {
883 }
884 }
885
886 /**
887 * @hide
888 */
889 public boolean clearApplicationUserData(String packageName, IPackageDataObserver observer) {
890 try {
891 return ActivityManagerNative.getDefault().clearApplicationUserData(packageName,
892 observer);
893 } catch (RemoteException e) {
894 return false;
895 }
896 }
897
898 /**
899 * Information you can retrieve about any processes that are in an error condition.
900 */
901 public static class ProcessErrorStateInfo implements Parcelable {
902 /**
903 * Condition codes
904 */
905 public static final int NO_ERROR = 0;
906 public static final int CRASHED = 1;
907 public static final int NOT_RESPONDING = 2;
908
909 /**
910 * The condition that the process is in.
911 */
912 public int condition;
913
914 /**
915 * The process name in which the crash or error occurred.
916 */
917 public String processName;
918
919 /**
920 * The pid of this process; 0 if none
921 */
922 public int pid;
923
924 /**
925 * The kernel user-ID that has been assigned to this process;
926 * currently this is not a unique ID (multiple applications can have
927 * the same uid).
928 */
929 public int uid;
930
931 /**
Dan Egnor60d87622009-12-16 16:32:58 -0800932 * The activity name associated with the error, if known. May be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800933 */
934 public String tag;
935
936 /**
937 * A short message describing the error condition.
938 */
939 public String shortMsg;
940
941 /**
942 * A long message describing the error condition.
943 */
944 public String longMsg;
945
946 /**
Dan Egnorb7f03672009-12-09 16:22:32 -0800947 * The stack trace where the error originated. May be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800948 */
Dan Egnorb7f03672009-12-09 16:22:32 -0800949 public String stackTrace;
950
951 /**
952 * to be deprecated: This value will always be null.
953 */
954 public byte[] crashData = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800955
956 public ProcessErrorStateInfo() {
957 }
958
959 public int describeContents() {
960 return 0;
961 }
962
963 public void writeToParcel(Parcel dest, int flags) {
964 dest.writeInt(condition);
965 dest.writeString(processName);
966 dest.writeInt(pid);
967 dest.writeInt(uid);
968 dest.writeString(tag);
969 dest.writeString(shortMsg);
970 dest.writeString(longMsg);
Dan Egnorb7f03672009-12-09 16:22:32 -0800971 dest.writeString(stackTrace);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800972 }
973
974 public void readFromParcel(Parcel source) {
975 condition = source.readInt();
976 processName = source.readString();
977 pid = source.readInt();
978 uid = source.readInt();
979 tag = source.readString();
980 shortMsg = source.readString();
981 longMsg = source.readString();
Dan Egnorb7f03672009-12-09 16:22:32 -0800982 stackTrace = source.readString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800983 }
984
985 public static final Creator<ProcessErrorStateInfo> CREATOR =
986 new Creator<ProcessErrorStateInfo>() {
987 public ProcessErrorStateInfo createFromParcel(Parcel source) {
988 return new ProcessErrorStateInfo(source);
989 }
990 public ProcessErrorStateInfo[] newArray(int size) {
991 return new ProcessErrorStateInfo[size];
992 }
993 };
994
995 private ProcessErrorStateInfo(Parcel source) {
996 readFromParcel(source);
997 }
998 }
999
1000 /**
1001 * Returns a list of any processes that are currently in an error condition. The result
1002 * will be null if all processes are running properly at this time.
1003 *
1004 * @return Returns a list of ProcessErrorStateInfo records, or null if there are no
1005 * current error conditions (it will not return an empty list). This list ordering is not
1006 * specified.
1007 */
1008 public List<ProcessErrorStateInfo> getProcessesInErrorState() {
1009 try {
1010 return ActivityManagerNative.getDefault().getProcessesInErrorState();
1011 } catch (RemoteException e) {
1012 return null;
1013 }
1014 }
1015
1016 /**
1017 * Information you can retrieve about a running process.
1018 */
1019 public static class RunningAppProcessInfo implements Parcelable {
1020 /**
1021 * The name of the process that this object is associated with
1022 */
1023 public String processName;
1024
1025 /**
1026 * The pid of this process; 0 if none
1027 */
1028 public int pid;
1029
Dianne Hackborneb034652009-09-07 00:49:58 -07001030 /**
1031 * The user id of this process.
1032 */
1033 public int uid;
1034
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07001035 /**
1036 * All packages that have been loaded into the process.
1037 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001038 public String pkgList[];
1039
1040 /**
Dianne Hackborn482566e2010-09-03 12:51:28 -07001041 * Constant for {@link #flags}: this is an app that is unable to
1042 * correctly save its state when going to the background,
1043 * so it can not be killed while in the background.
1044 * @hide
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07001045 */
Dianne Hackborn482566e2010-09-03 12:51:28 -07001046 public static final int FLAG_CANT_SAVE_STATE = 1<<0;
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07001047
1048 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07001049 * Constant for {@link #flags}: this process is associated with a
1050 * persistent system app.
1051 * @hide
1052 */
1053 public static final int FLAG_PERSISTENT = 1<<1;
1054
1055 /**
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07001056 * Flags of information. May be any of
Dianne Hackborn482566e2010-09-03 12:51:28 -07001057 * {@link #FLAG_CANT_SAVE_STATE}.
1058 * @hide
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07001059 */
1060 public int flags;
1061
1062 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001063 * Constant for {@link #importance}: this process is running the
1064 * foreground UI.
1065 */
1066 public static final int IMPORTANCE_FOREGROUND = 100;
1067
1068 /**
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001069 * Constant for {@link #importance}: this process is running something
1070 * that is actively visible to the user, though not in the immediate
1071 * foreground.
Dianne Hackborn860755f2010-06-03 18:47:52 -07001072 */
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001073 public static final int IMPORTANCE_VISIBLE = 200;
Dianne Hackborn860755f2010-06-03 18:47:52 -07001074
1075 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001076 * Constant for {@link #importance}: this process is running something
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001077 * that is considered to be actively perceptible to the user. An
1078 * example would be an application performing background music playback.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001079 */
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001080 public static final int IMPORTANCE_PERCEPTIBLE = 130;
1081
1082 /**
Dianne Hackborn5383f502010-10-22 12:59:20 -07001083 * Constant for {@link #importance}: this process is running an
1084 * application that can not save its state, and thus can't be killed
1085 * while in the background.
1086 * @hide
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001087 */
Dianne Hackborn5383f502010-10-22 12:59:20 -07001088 public static final int IMPORTANCE_CANT_SAVE_STATE = 170;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001089
1090 /**
1091 * Constant for {@link #importance}: this process is contains services
1092 * that should remain running.
1093 */
1094 public static final int IMPORTANCE_SERVICE = 300;
1095
1096 /**
1097 * Constant for {@link #importance}: this process process contains
1098 * background code that is expendable.
1099 */
1100 public static final int IMPORTANCE_BACKGROUND = 400;
1101
1102 /**
1103 * Constant for {@link #importance}: this process is empty of any
1104 * actively running code.
1105 */
1106 public static final int IMPORTANCE_EMPTY = 500;
1107
1108 /**
1109 * The relative importance level that the system places on this
1110 * process. May be one of {@link #IMPORTANCE_FOREGROUND},
1111 * {@link #IMPORTANCE_VISIBLE}, {@link #IMPORTANCE_SERVICE},
1112 * {@link #IMPORTANCE_BACKGROUND}, or {@link #IMPORTANCE_EMPTY}. These
1113 * constants are numbered so that "more important" values are always
1114 * smaller than "less important" values.
1115 */
1116 public int importance;
1117
1118 /**
1119 * An additional ordering within a particular {@link #importance}
1120 * category, providing finer-grained information about the relative
1121 * utility of processes within a category. This number means nothing
1122 * except that a smaller values are more recently used (and thus
1123 * more important). Currently an LRU value is only maintained for
1124 * the {@link #IMPORTANCE_BACKGROUND} category, though others may
1125 * be maintained in the future.
1126 */
1127 public int lru;
1128
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07001129 /**
1130 * Constant for {@link #importanceReasonCode}: nothing special has
1131 * been specified for the reason for this level.
1132 */
1133 public static final int REASON_UNKNOWN = 0;
1134
1135 /**
1136 * Constant for {@link #importanceReasonCode}: one of the application's
1137 * content providers is being used by another process. The pid of
1138 * the client process is in {@link #importanceReasonPid} and the
1139 * target provider in this process is in
1140 * {@link #importanceReasonComponent}.
1141 */
1142 public static final int REASON_PROVIDER_IN_USE = 1;
1143
1144 /**
1145 * Constant for {@link #importanceReasonCode}: one of the application's
1146 * content providers is being used by another process. The pid of
1147 * the client process is in {@link #importanceReasonPid} and the
1148 * target provider in this process is in
1149 * {@link #importanceReasonComponent}.
1150 */
1151 public static final int REASON_SERVICE_IN_USE = 2;
1152
1153 /**
1154 * The reason for {@link #importance}, if any.
1155 */
1156 public int importanceReasonCode;
1157
1158 /**
1159 * For the specified values of {@link #importanceReasonCode}, this
1160 * is the process ID of the other process that is a client of this
1161 * process. This will be 0 if no other process is using this one.
1162 */
1163 public int importanceReasonPid;
1164
1165 /**
1166 * For the specified values of {@link #importanceReasonCode}, this
1167 * is the name of the component that is being used in this process.
1168 */
1169 public ComponentName importanceReasonComponent;
1170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001171 public RunningAppProcessInfo() {
1172 importance = IMPORTANCE_FOREGROUND;
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07001173 importanceReasonCode = REASON_UNKNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001174 }
1175
1176 public RunningAppProcessInfo(String pProcessName, int pPid, String pArr[]) {
1177 processName = pProcessName;
1178 pid = pPid;
1179 pkgList = pArr;
1180 }
1181
1182 public int describeContents() {
1183 return 0;
1184 }
1185
1186 public void writeToParcel(Parcel dest, int flags) {
1187 dest.writeString(processName);
1188 dest.writeInt(pid);
Dianne Hackborneb034652009-09-07 00:49:58 -07001189 dest.writeInt(uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001190 dest.writeStringArray(pkgList);
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07001191 dest.writeInt(this.flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001192 dest.writeInt(importance);
1193 dest.writeInt(lru);
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07001194 dest.writeInt(importanceReasonCode);
1195 dest.writeInt(importanceReasonPid);
1196 ComponentName.writeToParcel(importanceReasonComponent, dest);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001197 }
1198
1199 public void readFromParcel(Parcel source) {
1200 processName = source.readString();
1201 pid = source.readInt();
Dianne Hackborneb034652009-09-07 00:49:58 -07001202 uid = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001203 pkgList = source.readStringArray();
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07001204 flags = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001205 importance = source.readInt();
1206 lru = source.readInt();
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07001207 importanceReasonCode = source.readInt();
1208 importanceReasonPid = source.readInt();
1209 importanceReasonComponent = ComponentName.readFromParcel(source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001210 }
1211
1212 public static final Creator<RunningAppProcessInfo> CREATOR =
1213 new Creator<RunningAppProcessInfo>() {
1214 public RunningAppProcessInfo createFromParcel(Parcel source) {
1215 return new RunningAppProcessInfo(source);
1216 }
1217 public RunningAppProcessInfo[] newArray(int size) {
1218 return new RunningAppProcessInfo[size];
1219 }
1220 };
1221
1222 private RunningAppProcessInfo(Parcel source) {
1223 readFromParcel(source);
1224 }
1225 }
1226
1227 /**
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -07001228 * Returns a list of application processes installed on external media
1229 * that are running on the device.
1230 *
1231 * @return Returns a list of ApplicationInfo records, or null if none
1232 * This list ordering is not specified.
1233 * @hide
1234 */
1235 public List<ApplicationInfo> getRunningExternalApplications() {
1236 try {
1237 return ActivityManagerNative.getDefault().getRunningExternalApplications();
1238 } catch (RemoteException e) {
1239 return null;
1240 }
1241 }
1242
1243 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001244 * Returns a list of application processes that are running on the device.
1245 *
1246 * @return Returns a list of RunningAppProcessInfo records, or null if there are no
1247 * running processes (it will not return an empty list). This list ordering is not
1248 * specified.
1249 */
1250 public List<RunningAppProcessInfo> getRunningAppProcesses() {
1251 try {
1252 return ActivityManagerNative.getDefault().getRunningAppProcesses();
1253 } catch (RemoteException e) {
1254 return null;
1255 }
1256 }
1257
1258 /**
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07001259 * Return information about the memory usage of one or more processes.
1260 *
1261 * @param pids The pids of the processes whose memory usage is to be
1262 * retrieved.
1263 * @return Returns an array of memory information, one for each
1264 * requested pid.
1265 */
1266 public Debug.MemoryInfo[] getProcessMemoryInfo(int[] pids) {
1267 try {
1268 return ActivityManagerNative.getDefault().getProcessMemoryInfo(pids);
1269 } catch (RemoteException e) {
1270 return null;
1271 }
1272 }
1273
1274 /**
Dianne Hackborn03abb812010-01-04 18:43:19 -08001275 * @deprecated This is now just a wrapper for
1276 * {@link #killBackgroundProcesses(String)}; the previous behavior here
1277 * is no longer available to applications because it allows them to
1278 * break other applications by removing their alarms, stopping their
1279 * services, etc.
1280 */
1281 @Deprecated
1282 public void restartPackage(String packageName) {
1283 killBackgroundProcesses(packageName);
1284 }
1285
1286 /**
1287 * Have the system immediately kill all background processes associated
1288 * with the given package. This is the same as the kernel killing those
1289 * processes to reclaim memory; the system will take care of restarting
1290 * these processes in the future as needed.
1291 *
1292 * <p>You must hold the permission
1293 * {@link android.Manifest.permission#KILL_BACKGROUND_PROCESSES} to be able to
1294 * call this method.
1295 *
1296 * @param packageName The name of the package whose processes are to
1297 * be killed.
1298 */
1299 public void killBackgroundProcesses(String packageName) {
1300 try {
1301 ActivityManagerNative.getDefault().killBackgroundProcesses(packageName);
1302 } catch (RemoteException e) {
1303 }
1304 }
1305
1306 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001307 * Have the system perform a force stop of everything associated with
1308 * the given application package. All processes that share its uid
1309 * will be killed, all services it has running stopped, all activities
1310 * removed, etc. In addition, a {@link Intent#ACTION_PACKAGE_RESTARTED}
1311 * broadcast will be sent, so that any of its registered alarms can
1312 * be stopped, notifications removed, etc.
1313 *
1314 * <p>You must hold the permission
Dianne Hackborn03abb812010-01-04 18:43:19 -08001315 * {@link android.Manifest.permission#FORCE_STOP_PACKAGES} to be able to
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001316 * call this method.
1317 *
1318 * @param packageName The name of the package to be stopped.
Dianne Hackborn03abb812010-01-04 18:43:19 -08001319 *
1320 * @hide This is not available to third party applications due to
1321 * it allowing them to break other applications by stopping their
1322 * services, removing their alarms, etc.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001323 */
Dianne Hackborn03abb812010-01-04 18:43:19 -08001324 public void forceStopPackage(String packageName) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001325 try {
Dianne Hackborn03abb812010-01-04 18:43:19 -08001326 ActivityManagerNative.getDefault().forceStopPackage(packageName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001327 } catch (RemoteException e) {
1328 }
1329 }
1330
1331 /**
1332 * Get the device configuration attributes.
1333 */
1334 public ConfigurationInfo getDeviceConfigurationInfo() {
1335 try {
1336 return ActivityManagerNative.getDefault().getDeviceConfigurationInfo();
1337 } catch (RemoteException e) {
1338 }
1339 return null;
1340 }
Kenny Root5ef44b72011-01-26 17:22:20 -08001341
1342 /**
1343 * Get the preferred density of icons for the launcher. This is used when
1344 * custom drawables are created (e.g., for shortcuts).
1345 *
1346 * @return density in terms of DPI
1347 */
1348 public int getLauncherLargeIconDensity() {
1349 final Resources res = mContext.getResources();
1350 final int density = res.getDisplayMetrics().densityDpi;
1351
1352 if ((res.getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK)
1353 != Configuration.SCREENLAYOUT_SIZE_XLARGE) {
1354 return density;
1355 }
1356
1357 switch (density) {
1358 case DisplayMetrics.DENSITY_LOW:
1359 return DisplayMetrics.DENSITY_MEDIUM;
1360 case DisplayMetrics.DENSITY_MEDIUM:
1361 return DisplayMetrics.DENSITY_HIGH;
1362 case DisplayMetrics.DENSITY_HIGH:
1363 return DisplayMetrics.DENSITY_XHIGH;
1364 case DisplayMetrics.DENSITY_XHIGH:
1365 return DisplayMetrics.DENSITY_MEDIUM * 2;
1366 default:
1367 return density;
1368 }
1369 }
1370
1371 /**
1372 * Get the preferred launcher icon size. This is used when custom drawables
1373 * are created (e.g., for shortcuts).
1374 *
1375 * @return dimensions of square icons in terms of pixels
1376 */
1377 public int getLauncherLargeIconSize() {
1378 final Resources res = mContext.getResources();
1379 final int size = res.getDimensionPixelSize(android.R.dimen.app_icon_size);
1380
1381 if ((res.getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK)
1382 != Configuration.SCREENLAYOUT_SIZE_XLARGE) {
1383 return size;
1384 }
1385
1386 final int density = res.getDisplayMetrics().densityDpi;
1387
1388 switch (density) {
1389 case DisplayMetrics.DENSITY_LOW:
1390 return (size * DisplayMetrics.DENSITY_MEDIUM) / DisplayMetrics.DENSITY_LOW;
1391 case DisplayMetrics.DENSITY_MEDIUM:
1392 return (size * DisplayMetrics.DENSITY_HIGH) / DisplayMetrics.DENSITY_MEDIUM;
1393 case DisplayMetrics.DENSITY_HIGH:
1394 return (size * DisplayMetrics.DENSITY_XHIGH) / DisplayMetrics.DENSITY_HIGH;
1395 case DisplayMetrics.DENSITY_XHIGH:
1396 return (size * DisplayMetrics.DENSITY_MEDIUM * 2) / DisplayMetrics.DENSITY_XHIGH;
1397 default:
1398 return size;
1399 }
1400 }
1401
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001402 /**
1403 * Returns "true" if the user interface is currently being messed with
1404 * by a monkey.
1405 */
1406 public static boolean isUserAMonkey() {
1407 try {
1408 return ActivityManagerNative.getDefault().isUserAMonkey();
1409 } catch (RemoteException e) {
1410 }
1411 return false;
1412 }
Brett Chabot3b4fcbc2011-01-09 13:41:02 -08001413
1414 /**
1415 * Returns "true" if device is running in a test harness.
1416 */
1417 public static boolean isRunningInTestHarness() {
1418 return SystemProperties.getBoolean("ro.test_harness", false);
1419 }
Peter Visontay8d224ca2011-02-18 16:39:19 +00001420
1421 /**
1422 * Returns the launch count of each installed package.
1423 *
1424 * @hide
1425 */
1426 public Map<String, Integer> getAllPackageLaunchCounts() {
1427 try {
1428 IUsageStats usageStatsService = IUsageStats.Stub.asInterface(
1429 ServiceManager.getService("usagestats"));
1430 if (usageStatsService == null) {
1431 return new HashMap<String, Integer>();
1432 }
1433
Peter Visontaybfcda392011-03-02 18:53:37 +00001434 PkgUsageStats[] allPkgUsageStats = usageStatsService.getAllPkgUsageStats();
1435 if (allPkgUsageStats == null) {
1436 return new HashMap<String, Integer>();
1437 }
1438
Peter Visontay8d224ca2011-02-18 16:39:19 +00001439 Map<String, Integer> launchCounts = new HashMap<String, Integer>();
Peter Visontaybfcda392011-03-02 18:53:37 +00001440 for (PkgUsageStats pkgUsageStats : allPkgUsageStats) {
Peter Visontay8d224ca2011-02-18 16:39:19 +00001441 launchCounts.put(pkgUsageStats.packageName, pkgUsageStats.launchCount);
1442 }
1443
1444 return launchCounts;
1445 } catch (RemoteException e) {
1446 Log.w(TAG, "Could not query launch counts", e);
1447 return new HashMap<String, Integer>();
1448 }
1449 }
Amith Yamasani4b2e9342011-03-31 12:38:53 -07001450
1451 /**
1452 * @param userid the user's id. Zero indicates the default user
1453 * @hide
1454 */
1455 public boolean switchUser(int userid) {
1456 try {
1457 return ActivityManagerNative.getDefault().switchUser(userid);
1458 } catch (RemoteException e) {
1459 return false;
1460 }
1461 }
1462
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001463}