ActivityManager.java revision de39851592679a545b8b6fb749507ccc7ec407f9
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
17package android.app;
18
19import android.content.ComponentName;
20import android.content.Context;
21import android.content.Intent;
22import android.content.pm.ApplicationInfo;
23import android.content.pm.ConfigurationInfo;
24import android.content.pm.IPackageDataObserver;
25import android.graphics.Bitmap;
26import android.os.Debug;
27import android.os.RemoteException;
28import android.os.Handler;
29import android.os.Parcel;
30import android.os.Parcelable;
31import android.os.SystemProperties;
32import android.text.TextUtils;
33import java.util.List;
34
35/**
36 * Interact with the overall activities running in the system.
37 */
38public class ActivityManager {
39    private static String TAG = "ActivityManager";
40    private static boolean DEBUG = false;
41    private static boolean localLOGV = DEBUG || android.util.Config.LOGV;
42
43    private final Context mContext;
44    private final Handler mHandler;
45
46    /*package*/ ActivityManager(Context context, Handler handler) {
47        mContext = context;
48        mHandler = handler;
49    }
50
51    /**
52     * Return the approximate per-application memory class of the current
53     * device.  This gives you an idea of how hard a memory limit you should
54     * impose on your application to let the overall system work best.  The
55     * returned value is in megabytes; the baseline Android memory class is
56     * 16 (which happens to be the Java heap limit of those devices); some
57     * device with more memory may return 24 or even higher numbers.
58     */
59    public int getMemoryClass() {
60        return staticGetMemoryClass();
61    }
62
63    /** @hide */
64    static public int staticGetMemoryClass() {
65        // Really brain dead right now -- just take this from the configured
66        // vm heap size, and assume it is in megabytes and thus ends with "m".
67        String vmHeapSize = SystemProperties.get("dalvik.vm.growthlimit", "");
68        if (vmHeapSize != null && !"".equals(vmHeapSize)) {
69            return Integer.parseInt(vmHeapSize.substring(0, vmHeapSize.length()-1));
70        }
71        return staticGetLargeMemoryClass();
72    }
73
74    /**
75     * Return the approximate per-application memory class of the current
76     * device when an application is running with a large heap.  This is the
77     * space available for memory-intensive applications; most applications
78     * should not need this amount of memory, and should instead stay with the
79     * {@link #getMemoryClass()} limit.  The returned value is in megabytes.
80     * This may be the same size as {@link #getMemoryClass()} on memory
81     * constrained devices, or it may be significantly larger on devices with
82     * a large amount of available RAM.
83     *
84     * <p>The is the size of the application's Dalvik heap if it has
85     * specified <code>android:largeHeap="true"</code> in its manifest.
86     */
87    public int getLargeMemoryClass() {
88        return staticGetLargeMemoryClass();
89    }
90
91    /** @hide */
92    static public int staticGetLargeMemoryClass() {
93        // Really brain dead right now -- just take this from the configured
94        // vm heap size, and assume it is in megabytes and thus ends with "m".
95        String vmHeapSize = SystemProperties.get("dalvik.vm.heapsize", "16m");
96        return Integer.parseInt(vmHeapSize.substring(0, vmHeapSize.length()-1));
97    }
98
99    /**
100     * Information you can retrieve about tasks that the user has most recently
101     * started or visited.
102     */
103    public static class RecentTaskInfo implements Parcelable {
104        /**
105         * If this task is currently running, this is the identifier for it.
106         * If it is not running, this will be -1.
107         */
108        public int id;
109
110        /**
111         * The original Intent used to launch the task.  You can use this
112         * Intent to re-launch the task (if it is no longer running) or bring
113         * the current task to the front.
114         */
115        public Intent baseIntent;
116
117        /**
118         * If this task was started from an alias, this is the actual
119         * activity component that was initially started; the component of
120         * the baseIntent in this case is the name of the actual activity
121         * implementation that the alias referred to.  Otherwise, this is null.
122         */
123        public ComponentName origActivity;
124
125        /**
126         * Thumbnail representation of the task's last state.  Must
127         * use {@link ActivityManager#TASKS_GET_THUMBNAILS} to have this set.
128         * @hide -- this is not scalable, need to have a separate API to get
129         * the bitmap.
130         */
131        public Bitmap thumbnail;
132
133        /**
134         * Description of the task's last state.
135         */
136        public CharSequence description;
137
138        public RecentTaskInfo() {
139        }
140
141        public int describeContents() {
142            return 0;
143        }
144
145        public void writeToParcel(Parcel dest, int flags) {
146            dest.writeInt(id);
147            if (baseIntent != null) {
148                dest.writeInt(1);
149                baseIntent.writeToParcel(dest, 0);
150            } else {
151                dest.writeInt(0);
152            }
153            ComponentName.writeToParcel(origActivity, dest);
154            if (thumbnail != null) {
155                dest.writeInt(1);
156                thumbnail.writeToParcel(dest, 0);
157            } else {
158                dest.writeInt(0);
159            }
160            TextUtils.writeToParcel(description, dest,
161                    Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
162        }
163
164        public void readFromParcel(Parcel source) {
165            id = source.readInt();
166            if (source.readInt() != 0) {
167                baseIntent = Intent.CREATOR.createFromParcel(source);
168            } else {
169                baseIntent = null;
170            }
171            origActivity = ComponentName.readFromParcel(source);
172            if (source.readInt() != 0) {
173                thumbnail = Bitmap.CREATOR.createFromParcel(source);
174            } else {
175                thumbnail = null;
176            }
177            description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
178        }
179
180        public static final Creator<RecentTaskInfo> CREATOR
181                = new Creator<RecentTaskInfo>() {
182            public RecentTaskInfo createFromParcel(Parcel source) {
183                return new RecentTaskInfo(source);
184            }
185            public RecentTaskInfo[] newArray(int size) {
186                return new RecentTaskInfo[size];
187            }
188        };
189
190        private RecentTaskInfo(Parcel source) {
191            readFromParcel(source);
192        }
193    }
194
195    /**
196     * Flag for use with {@link #getRecentTasks}: return all tasks, even those
197     * that have set their
198     * {@link android.content.Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} flag.
199     */
200    public static final int RECENT_WITH_EXCLUDED = 0x0001;
201
202    /**
203     * Provides a list that does not contain any
204     * recent tasks that currently are not available to the user.
205     */
206    public static final int RECENT_IGNORE_UNAVAILABLE = 0x0002;
207
208    /**
209     * Flag for use with {@link #getRecentTasks}: also return the thumbnail
210     * bitmap (if available) for each recent task.
211     * @hide
212     */
213    public static final int TASKS_GET_THUMBNAILS = 0x0001000;
214
215    /**
216     * Return a list of the tasks that the user has recently launched, with
217     * the most recent being first and older ones after in order.
218     *
219     * @param maxNum The maximum number of entries to return in the list.  The
220     * actual number returned may be smaller, depending on how many tasks the
221     * user has started and the maximum number the system can remember.
222     * @param flags Information about what to return.  May be any combination
223     * of {@link #RECENT_WITH_EXCLUDED} and {@link #RECENT_IGNORE_UNAVAILABLE}.
224     *
225     * @return Returns a list of RecentTaskInfo records describing each of
226     * the recent tasks.
227     *
228     * @throws SecurityException Throws SecurityException if the caller does
229     * not hold the {@link android.Manifest.permission#GET_TASKS} permission.
230     */
231    public List<RecentTaskInfo> getRecentTasks(int maxNum, int flags)
232            throws SecurityException {
233        try {
234            return ActivityManagerNative.getDefault().getRecentTasks(maxNum,
235                    flags);
236        } catch (RemoteException e) {
237            // System dead, we will be dead too soon!
238            return null;
239        }
240    }
241
242    /**
243     * Information you can retrieve about a particular task that is currently
244     * "running" in the system.  Note that a running task does not mean the
245     * given task actual has a process it is actively running in; it simply
246     * means that the user has gone to it and never closed it, but currently
247     * the system may have killed its process and is only holding on to its
248     * last state in order to restart it when the user returns.
249     */
250    public static class RunningTaskInfo implements Parcelable {
251        /**
252         * A unique identifier for this task.
253         */
254        public int id;
255
256        /**
257         * The component launched as the first activity in the task.  This can
258         * be considered the "application" of this task.
259         */
260        public ComponentName baseActivity;
261
262        /**
263         * The activity component at the top of the history stack of the task.
264         * This is what the user is currently doing.
265         */
266        public ComponentName topActivity;
267
268        /**
269         * Thumbnail representation of the task's current state.  Currently
270         * always null.
271         */
272        public Bitmap thumbnail;
273
274        /**
275         * Description of the task's current state.
276         */
277        public CharSequence description;
278
279        /**
280         * Number of activities in this task.
281         */
282        public int numActivities;
283
284        /**
285         * Number of activities that are currently running (not stopped
286         * and persisted) in this task.
287         */
288        public int numRunning;
289
290        public RunningTaskInfo() {
291        }
292
293        public int describeContents() {
294            return 0;
295        }
296
297        public void writeToParcel(Parcel dest, int flags) {
298            dest.writeInt(id);
299            ComponentName.writeToParcel(baseActivity, dest);
300            ComponentName.writeToParcel(topActivity, dest);
301            if (thumbnail != null) {
302                dest.writeInt(1);
303                thumbnail.writeToParcel(dest, 0);
304            } else {
305                dest.writeInt(0);
306            }
307            TextUtils.writeToParcel(description, dest,
308                    Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
309            dest.writeInt(numActivities);
310            dest.writeInt(numRunning);
311        }
312
313        public void readFromParcel(Parcel source) {
314            id = source.readInt();
315            baseActivity = ComponentName.readFromParcel(source);
316            topActivity = ComponentName.readFromParcel(source);
317            if (source.readInt() != 0) {
318                thumbnail = Bitmap.CREATOR.createFromParcel(source);
319            } else {
320                thumbnail = null;
321            }
322            description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
323            numActivities = source.readInt();
324            numRunning = source.readInt();
325        }
326
327        public static final Creator<RunningTaskInfo> CREATOR = new Creator<RunningTaskInfo>() {
328            public RunningTaskInfo createFromParcel(Parcel source) {
329                return new RunningTaskInfo(source);
330            }
331            public RunningTaskInfo[] newArray(int size) {
332                return new RunningTaskInfo[size];
333            }
334        };
335
336        private RunningTaskInfo(Parcel source) {
337            readFromParcel(source);
338        }
339    }
340
341    /**
342     * Return a list of the tasks that are currently running, with
343     * the most recent being first and older ones after in order.  Note that
344     * "running" does not mean any of the task's code is currently loaded or
345     * activity -- the task may have been frozen by the system, so that it
346     * can be restarted in its previous state when next brought to the
347     * foreground.
348     *
349     * @param maxNum The maximum number of entries to return in the list.  The
350     * actual number returned may be smaller, depending on how many tasks the
351     * user has started.
352     *
353     * @param flags Optional flags
354     * @param receiver Optional receiver for delayed thumbnails
355     *
356     * @return Returns a list of RunningTaskInfo records describing each of
357     * the running tasks.
358     *
359     * Some thumbnails may not be available at the time of this call. The optional
360     * receiver may be used to receive those thumbnails.
361     *
362     * @throws SecurityException Throws SecurityException if the caller does
363     * not hold the {@link android.Manifest.permission#GET_TASKS} permission.
364     *
365     * @hide
366     */
367    public List<RunningTaskInfo> getRunningTasks(int maxNum, int flags, IThumbnailReceiver receiver)
368            throws SecurityException {
369        try {
370            return ActivityManagerNative.getDefault().getTasks(maxNum, flags, receiver);
371        } catch (RemoteException e) {
372            // System dead, we will be dead too soon!
373            return null;
374        }
375    }
376
377    /**
378     * Return a list of the tasks that are currently running, with
379     * the most recent being first and older ones after in order.  Note that
380     * "running" does not mean any of the task's code is currently loaded or
381     * activity -- the task may have been frozen by the system, so that it
382     * can be restarted in its previous state when next brought to the
383     * foreground.
384     *
385     * @param maxNum The maximum number of entries to return in the list.  The
386     * actual number returned may be smaller, depending on how many tasks the
387     * user has started.
388     *
389     * @return Returns a list of RunningTaskInfo records describing each of
390     * the running tasks.
391     *
392     * @throws SecurityException Throws SecurityException if the caller does
393     * not hold the {@link android.Manifest.permission#GET_TASKS} permission.
394     */
395    public List<RunningTaskInfo> getRunningTasks(int maxNum)
396            throws SecurityException {
397        return getRunningTasks(maxNum, 0, null);
398    }
399
400    /**
401     * Flag for {@link #moveTaskToFront(int, int)}: also move the "home"
402     * activity along with the task, so it is positioned immediately behind
403     * the task.
404     */
405    public static final int MOVE_TASK_WITH_HOME = 0x00000001;
406
407    /**
408     * Ask that the task associated with a given task ID be moved to the
409     * front of the stack, so it is now visible to the user.  Requires that
410     * the caller hold permission {@link android.Manifest.permission#REORDER_TASKS}
411     * or a SecurityException will be thrown.
412     *
413     * @param taskId The identifier of the task to be moved, as found in
414     * {@link RunningTaskInfo} or {@link RecentTaskInfo}.
415     * @param flags Additional operational flags, 0 or more of
416     * {@link #MOVE_TASK_WITH_HOME}.
417     */
418    public void moveTaskToFront(int taskId, int flags) {
419        try {
420            ActivityManagerNative.getDefault().moveTaskToFront(taskId, flags);
421        } catch (RemoteException e) {
422            // System dead, we will be dead too soon!
423        }
424    }
425
426    /**
427     * Information you can retrieve about a particular Service that is
428     * currently running in the system.
429     */
430    public static class RunningServiceInfo implements Parcelable {
431        /**
432         * The service component.
433         */
434        public ComponentName service;
435
436        /**
437         * If non-zero, this is the process the service is running in.
438         */
439        public int pid;
440
441        /**
442         * The UID that owns this service.
443         */
444        public int uid;
445
446        /**
447         * The name of the process this service runs in.
448         */
449        public String process;
450
451        /**
452         * Set to true if the service has asked to run as a foreground process.
453         */
454        public boolean foreground;
455
456        /**
457         * The time when the service was first made active, either by someone
458         * starting or binding to it.  This
459         * is in units of {@link android.os.SystemClock#elapsedRealtime()}.
460         */
461        public long activeSince;
462
463        /**
464         * Set to true if this service has been explicitly started.
465         */
466        public boolean started;
467
468        /**
469         * Number of clients connected to the service.
470         */
471        public int clientCount;
472
473        /**
474         * Number of times the service's process has crashed while the service
475         * is running.
476         */
477        public int crashCount;
478
479        /**
480         * The time when there was last activity in the service (either
481         * explicit requests to start it or clients binding to it).  This
482         * is in units of {@link android.os.SystemClock#uptimeMillis()}.
483         */
484        public long lastActivityTime;
485
486        /**
487         * If non-zero, this service is not currently running, but scheduled to
488         * restart at the given time.
489         */
490        public long restarting;
491
492        /**
493         * Bit for {@link #flags}: set if this service has been
494         * explicitly started.
495         */
496        public static final int FLAG_STARTED = 1<<0;
497
498        /**
499         * Bit for {@link #flags}: set if the service has asked to
500         * run as a foreground process.
501         */
502        public static final int FLAG_FOREGROUND = 1<<1;
503
504        /**
505         * Bit for {@link #flags): set if the service is running in a
506         * core system process.
507         */
508        public static final int FLAG_SYSTEM_PROCESS = 1<<2;
509
510        /**
511         * Bit for {@link #flags): set if the service is running in a
512         * persistent process.
513         */
514        public static final int FLAG_PERSISTENT_PROCESS = 1<<3;
515
516        /**
517         * Running flags.
518         */
519        public int flags;
520
521        /**
522         * For special services that are bound to by system code, this is
523         * the package that holds the binding.
524         */
525        public String clientPackage;
526
527        /**
528         * For special services that are bound to by system code, this is
529         * a string resource providing a user-visible label for who the
530         * client is.
531         */
532        public int clientLabel;
533
534        public RunningServiceInfo() {
535        }
536
537        public int describeContents() {
538            return 0;
539        }
540
541        public void writeToParcel(Parcel dest, int flags) {
542            ComponentName.writeToParcel(service, dest);
543            dest.writeInt(pid);
544            dest.writeInt(uid);
545            dest.writeString(process);
546            dest.writeInt(foreground ? 1 : 0);
547            dest.writeLong(activeSince);
548            dest.writeInt(started ? 1 : 0);
549            dest.writeInt(clientCount);
550            dest.writeInt(crashCount);
551            dest.writeLong(lastActivityTime);
552            dest.writeLong(restarting);
553            dest.writeInt(this.flags);
554            dest.writeString(clientPackage);
555            dest.writeInt(clientLabel);
556        }
557
558        public void readFromParcel(Parcel source) {
559            service = ComponentName.readFromParcel(source);
560            pid = source.readInt();
561            uid = source.readInt();
562            process = source.readString();
563            foreground = source.readInt() != 0;
564            activeSince = source.readLong();
565            started = source.readInt() != 0;
566            clientCount = source.readInt();
567            crashCount = source.readInt();
568            lastActivityTime = source.readLong();
569            restarting = source.readLong();
570            flags = source.readInt();
571            clientPackage = source.readString();
572            clientLabel = source.readInt();
573        }
574
575        public static final Creator<RunningServiceInfo> CREATOR = new Creator<RunningServiceInfo>() {
576            public RunningServiceInfo createFromParcel(Parcel source) {
577                return new RunningServiceInfo(source);
578            }
579            public RunningServiceInfo[] newArray(int size) {
580                return new RunningServiceInfo[size];
581            }
582        };
583
584        private RunningServiceInfo(Parcel source) {
585            readFromParcel(source);
586        }
587    }
588
589    /**
590     * Return a list of the services that are currently running.
591     *
592     * @param maxNum The maximum number of entries to return in the list.  The
593     * actual number returned may be smaller, depending on how many services
594     * are running.
595     *
596     * @return Returns a list of RunningServiceInfo records describing each of
597     * the running tasks.
598     */
599    public List<RunningServiceInfo> getRunningServices(int maxNum)
600            throws SecurityException {
601        try {
602            return (List<RunningServiceInfo>)ActivityManagerNative.getDefault()
603                    .getServices(maxNum, 0);
604        } catch (RemoteException e) {
605            // System dead, we will be dead too soon!
606            return null;
607        }
608    }
609
610    /**
611     * Returns a PendingIntent you can start to show a control panel for the
612     * given running service.  If the service does not have a control panel,
613     * null is returned.
614     */
615    public PendingIntent getRunningServiceControlPanel(ComponentName service)
616            throws SecurityException {
617        try {
618            return ActivityManagerNative.getDefault()
619                    .getRunningServiceControlPanel(service);
620        } catch (RemoteException e) {
621            // System dead, we will be dead too soon!
622            return null;
623        }
624    }
625
626    /**
627     * Information you can retrieve about the available memory through
628     * {@link ActivityManager#getMemoryInfo}.
629     */
630    public static class MemoryInfo implements Parcelable {
631        /**
632         * The total available memory on the system.  This number should not
633         * be considered absolute: due to the nature of the kernel, a significant
634         * portion of this memory is actually in use and needed for the overall
635         * system to run well.
636         */
637        public long availMem;
638
639        /**
640         * The threshold of {@link #availMem} at which we consider memory to be
641         * low and start killing background services and other non-extraneous
642         * processes.
643         */
644        public long threshold;
645
646        /**
647         * Set to true if the system considers itself to currently be in a low
648         * memory situation.
649         */
650        public boolean lowMemory;
651
652        public MemoryInfo() {
653        }
654
655        public int describeContents() {
656            return 0;
657        }
658
659        public void writeToParcel(Parcel dest, int flags) {
660            dest.writeLong(availMem);
661            dest.writeLong(threshold);
662            dest.writeInt(lowMemory ? 1 : 0);
663        }
664
665        public void readFromParcel(Parcel source) {
666            availMem = source.readLong();
667            threshold = source.readLong();
668            lowMemory = source.readInt() != 0;
669        }
670
671        public static final Creator<MemoryInfo> CREATOR
672                = new Creator<MemoryInfo>() {
673            public MemoryInfo createFromParcel(Parcel source) {
674                return new MemoryInfo(source);
675            }
676            public MemoryInfo[] newArray(int size) {
677                return new MemoryInfo[size];
678            }
679        };
680
681        private MemoryInfo(Parcel source) {
682            readFromParcel(source);
683        }
684    }
685
686    public void getMemoryInfo(MemoryInfo outInfo) {
687        try {
688            ActivityManagerNative.getDefault().getMemoryInfo(outInfo);
689        } catch (RemoteException e) {
690        }
691    }
692
693    /**
694     * @hide
695     */
696    public boolean clearApplicationUserData(String packageName, IPackageDataObserver observer) {
697        try {
698            return ActivityManagerNative.getDefault().clearApplicationUserData(packageName,
699                    observer);
700        } catch (RemoteException e) {
701            return false;
702        }
703    }
704
705    /**
706     * Information you can retrieve about any processes that are in an error condition.
707     */
708    public static class ProcessErrorStateInfo implements Parcelable {
709        /**
710         * Condition codes
711         */
712        public static final int NO_ERROR = 0;
713        public static final int CRASHED = 1;
714        public static final int NOT_RESPONDING = 2;
715
716        /**
717         * The condition that the process is in.
718         */
719        public int condition;
720
721        /**
722         * The process name in which the crash or error occurred.
723         */
724        public String processName;
725
726        /**
727         * The pid of this process; 0 if none
728         */
729        public int pid;
730
731        /**
732         * The kernel user-ID that has been assigned to this process;
733         * currently this is not a unique ID (multiple applications can have
734         * the same uid).
735         */
736        public int uid;
737
738        /**
739         * The activity name associated with the error, if known.  May be null.
740         */
741        public String tag;
742
743        /**
744         * A short message describing the error condition.
745         */
746        public String shortMsg;
747
748        /**
749         * A long message describing the error condition.
750         */
751        public String longMsg;
752
753        /**
754         * The stack trace where the error originated.  May be null.
755         */
756        public String stackTrace;
757
758        /**
759         * to be deprecated: This value will always be null.
760         */
761        public byte[] crashData = null;
762
763        public ProcessErrorStateInfo() {
764        }
765
766        public int describeContents() {
767            return 0;
768        }
769
770        public void writeToParcel(Parcel dest, int flags) {
771            dest.writeInt(condition);
772            dest.writeString(processName);
773            dest.writeInt(pid);
774            dest.writeInt(uid);
775            dest.writeString(tag);
776            dest.writeString(shortMsg);
777            dest.writeString(longMsg);
778            dest.writeString(stackTrace);
779        }
780
781        public void readFromParcel(Parcel source) {
782            condition = source.readInt();
783            processName = source.readString();
784            pid = source.readInt();
785            uid = source.readInt();
786            tag = source.readString();
787            shortMsg = source.readString();
788            longMsg = source.readString();
789            stackTrace = source.readString();
790        }
791
792        public static final Creator<ProcessErrorStateInfo> CREATOR =
793                new Creator<ProcessErrorStateInfo>() {
794            public ProcessErrorStateInfo createFromParcel(Parcel source) {
795                return new ProcessErrorStateInfo(source);
796            }
797            public ProcessErrorStateInfo[] newArray(int size) {
798                return new ProcessErrorStateInfo[size];
799            }
800        };
801
802        private ProcessErrorStateInfo(Parcel source) {
803            readFromParcel(source);
804        }
805    }
806
807    /**
808     * Returns a list of any processes that are currently in an error condition.  The result
809     * will be null if all processes are running properly at this time.
810     *
811     * @return Returns a list of ProcessErrorStateInfo records, or null if there are no
812     * current error conditions (it will not return an empty list).  This list ordering is not
813     * specified.
814     */
815    public List<ProcessErrorStateInfo> getProcessesInErrorState() {
816        try {
817            return ActivityManagerNative.getDefault().getProcessesInErrorState();
818        } catch (RemoteException e) {
819            return null;
820        }
821    }
822
823    /**
824     * Information you can retrieve about a running process.
825     */
826    public static class RunningAppProcessInfo implements Parcelable {
827        /**
828         * The name of the process that this object is associated with
829         */
830        public String processName;
831
832        /**
833         * The pid of this process; 0 if none
834         */
835        public int pid;
836
837        /**
838         * The user id of this process.
839         */
840        public int uid;
841
842        /**
843         * All packages that have been loaded into the process.
844         */
845        public String pkgList[];
846
847        /**
848         * Constant for {@link #flags}: this is an app that is unable to
849         * correctly save its state when going to the background,
850         * so it can not be killed while in the background.
851         * @hide
852         */
853        public static final int FLAG_CANT_SAVE_STATE = 1<<0;
854
855        /**
856         * Constant for {@link #flags}: this process is associated with a
857         * persistent system app.
858         * @hide
859         */
860        public static final int FLAG_PERSISTENT = 1<<1;
861
862        /**
863         * Flags of information.  May be any of
864         * {@link #FLAG_CANT_SAVE_STATE}.
865         * @hide
866         */
867        public int flags;
868
869        /**
870         * Constant for {@link #importance}: this process is running the
871         * foreground UI.
872         */
873        public static final int IMPORTANCE_FOREGROUND = 100;
874
875        /**
876         * Constant for {@link #importance}: this process is running something
877         * that is actively visible to the user, though not in the immediate
878         * foreground.
879         */
880        public static final int IMPORTANCE_VISIBLE = 200;
881
882        /**
883         * Constant for {@link #importance}: this process is running something
884         * that is considered to be actively perceptible to the user.  An
885         * example would be an application performing background music playback.
886         */
887        public static final int IMPORTANCE_PERCEPTIBLE = 130;
888
889        /**
890         * Constant for {@link #importance}: this process is running an
891         * application that can not save its state, and thus can't be killed
892         * while in the background.
893         * @hide
894         */
895        public static final int IMPORTANCE_CANT_SAVE_STATE = 170;
896
897        /**
898         * Constant for {@link #importance}: this process is contains services
899         * that should remain running.
900         */
901        public static final int IMPORTANCE_SERVICE = 300;
902
903        /**
904         * Constant for {@link #importance}: this process process contains
905         * background code that is expendable.
906         */
907        public static final int IMPORTANCE_BACKGROUND = 400;
908
909        /**
910         * Constant for {@link #importance}: this process is empty of any
911         * actively running code.
912         */
913        public static final int IMPORTANCE_EMPTY = 500;
914
915        /**
916         * The relative importance level that the system places on this
917         * process.  May be one of {@link #IMPORTANCE_FOREGROUND},
918         * {@link #IMPORTANCE_VISIBLE}, {@link #IMPORTANCE_SERVICE},
919         * {@link #IMPORTANCE_BACKGROUND}, or {@link #IMPORTANCE_EMPTY}.  These
920         * constants are numbered so that "more important" values are always
921         * smaller than "less important" values.
922         */
923        public int importance;
924
925        /**
926         * An additional ordering within a particular {@link #importance}
927         * category, providing finer-grained information about the relative
928         * utility of processes within a category.  This number means nothing
929         * except that a smaller values are more recently used (and thus
930         * more important).  Currently an LRU value is only maintained for
931         * the {@link #IMPORTANCE_BACKGROUND} category, though others may
932         * be maintained in the future.
933         */
934        public int lru;
935
936        /**
937         * Constant for {@link #importanceReasonCode}: nothing special has
938         * been specified for the reason for this level.
939         */
940        public static final int REASON_UNKNOWN = 0;
941
942        /**
943         * Constant for {@link #importanceReasonCode}: one of the application's
944         * content providers is being used by another process.  The pid of
945         * the client process is in {@link #importanceReasonPid} and the
946         * target provider in this process is in
947         * {@link #importanceReasonComponent}.
948         */
949        public static final int REASON_PROVIDER_IN_USE = 1;
950
951        /**
952         * Constant for {@link #importanceReasonCode}: one of the application's
953         * content providers is being used by another process.  The pid of
954         * the client process is in {@link #importanceReasonPid} and the
955         * target provider in this process is in
956         * {@link #importanceReasonComponent}.
957         */
958        public static final int REASON_SERVICE_IN_USE = 2;
959
960        /**
961         * The reason for {@link #importance}, if any.
962         */
963        public int importanceReasonCode;
964
965        /**
966         * For the specified values of {@link #importanceReasonCode}, this
967         * is the process ID of the other process that is a client of this
968         * process.  This will be 0 if no other process is using this one.
969         */
970        public int importanceReasonPid;
971
972        /**
973         * For the specified values of {@link #importanceReasonCode}, this
974         * is the name of the component that is being used in this process.
975         */
976        public ComponentName importanceReasonComponent;
977
978        public RunningAppProcessInfo() {
979            importance = IMPORTANCE_FOREGROUND;
980            importanceReasonCode = REASON_UNKNOWN;
981        }
982
983        public RunningAppProcessInfo(String pProcessName, int pPid, String pArr[]) {
984            processName = pProcessName;
985            pid = pPid;
986            pkgList = pArr;
987        }
988
989        public int describeContents() {
990            return 0;
991        }
992
993        public void writeToParcel(Parcel dest, int flags) {
994            dest.writeString(processName);
995            dest.writeInt(pid);
996            dest.writeInt(uid);
997            dest.writeStringArray(pkgList);
998            dest.writeInt(this.flags);
999            dest.writeInt(importance);
1000            dest.writeInt(lru);
1001            dest.writeInt(importanceReasonCode);
1002            dest.writeInt(importanceReasonPid);
1003            ComponentName.writeToParcel(importanceReasonComponent, dest);
1004        }
1005
1006        public void readFromParcel(Parcel source) {
1007            processName = source.readString();
1008            pid = source.readInt();
1009            uid = source.readInt();
1010            pkgList = source.readStringArray();
1011            flags = source.readInt();
1012            importance = source.readInt();
1013            lru = source.readInt();
1014            importanceReasonCode = source.readInt();
1015            importanceReasonPid = source.readInt();
1016            importanceReasonComponent = ComponentName.readFromParcel(source);
1017        }
1018
1019        public static final Creator<RunningAppProcessInfo> CREATOR =
1020            new Creator<RunningAppProcessInfo>() {
1021            public RunningAppProcessInfo createFromParcel(Parcel source) {
1022                return new RunningAppProcessInfo(source);
1023            }
1024            public RunningAppProcessInfo[] newArray(int size) {
1025                return new RunningAppProcessInfo[size];
1026            }
1027        };
1028
1029        private RunningAppProcessInfo(Parcel source) {
1030            readFromParcel(source);
1031        }
1032    }
1033
1034    /**
1035     * Returns a list of application processes installed on external media
1036     * that are running on the device.
1037     *
1038     * @return Returns a list of ApplicationInfo records, or null if none
1039     * This list ordering is not specified.
1040     * @hide
1041     */
1042    public List<ApplicationInfo> getRunningExternalApplications() {
1043        try {
1044            return ActivityManagerNative.getDefault().getRunningExternalApplications();
1045        } catch (RemoteException e) {
1046            return null;
1047        }
1048    }
1049
1050    /**
1051     * Returns a list of application processes that are running on the device.
1052     *
1053     * @return Returns a list of RunningAppProcessInfo records, or null if there are no
1054     * running processes (it will not return an empty list).  This list ordering is not
1055     * specified.
1056     */
1057    public List<RunningAppProcessInfo> getRunningAppProcesses() {
1058        try {
1059            return ActivityManagerNative.getDefault().getRunningAppProcesses();
1060        } catch (RemoteException e) {
1061            return null;
1062        }
1063    }
1064
1065    /**
1066     * Return information about the memory usage of one or more processes.
1067     *
1068     * @param pids The pids of the processes whose memory usage is to be
1069     * retrieved.
1070     * @return Returns an array of memory information, one for each
1071     * requested pid.
1072     */
1073    public Debug.MemoryInfo[] getProcessMemoryInfo(int[] pids) {
1074        try {
1075            return ActivityManagerNative.getDefault().getProcessMemoryInfo(pids);
1076        } catch (RemoteException e) {
1077            return null;
1078        }
1079    }
1080
1081    /**
1082     * @deprecated This is now just a wrapper for
1083     * {@link #killBackgroundProcesses(String)}; the previous behavior here
1084     * is no longer available to applications because it allows them to
1085     * break other applications by removing their alarms, stopping their
1086     * services, etc.
1087     */
1088    @Deprecated
1089    public void restartPackage(String packageName) {
1090        killBackgroundProcesses(packageName);
1091    }
1092
1093    /**
1094     * Have the system immediately kill all background processes associated
1095     * with the given package.  This is the same as the kernel killing those
1096     * processes to reclaim memory; the system will take care of restarting
1097     * these processes in the future as needed.
1098     *
1099     * <p>You must hold the permission
1100     * {@link android.Manifest.permission#KILL_BACKGROUND_PROCESSES} to be able to
1101     * call this method.
1102     *
1103     * @param packageName The name of the package whose processes are to
1104     * be killed.
1105     */
1106    public void killBackgroundProcesses(String packageName) {
1107        try {
1108            ActivityManagerNative.getDefault().killBackgroundProcesses(packageName);
1109        } catch (RemoteException e) {
1110        }
1111    }
1112
1113    /**
1114     * Have the system perform a force stop of everything associated with
1115     * the given application package.  All processes that share its uid
1116     * will be killed, all services it has running stopped, all activities
1117     * removed, etc.  In addition, a {@link Intent#ACTION_PACKAGE_RESTARTED}
1118     * broadcast will be sent, so that any of its registered alarms can
1119     * be stopped, notifications removed, etc.
1120     *
1121     * <p>You must hold the permission
1122     * {@link android.Manifest.permission#FORCE_STOP_PACKAGES} to be able to
1123     * call this method.
1124     *
1125     * @param packageName The name of the package to be stopped.
1126     *
1127     * @hide This is not available to third party applications due to
1128     * it allowing them to break other applications by stopping their
1129     * services, removing their alarms, etc.
1130     */
1131    public void forceStopPackage(String packageName) {
1132        try {
1133            ActivityManagerNative.getDefault().forceStopPackage(packageName);
1134        } catch (RemoteException e) {
1135        }
1136    }
1137
1138    /**
1139     * Get the device configuration attributes.
1140     */
1141    public ConfigurationInfo getDeviceConfigurationInfo() {
1142        try {
1143            return ActivityManagerNative.getDefault().getDeviceConfigurationInfo();
1144        } catch (RemoteException e) {
1145        }
1146        return null;
1147    }
1148
1149    /**
1150     * Returns "true" if the user interface is currently being messed with
1151     * by a monkey.
1152     */
1153    public static boolean isUserAMonkey() {
1154        try {
1155            return ActivityManagerNative.getDefault().isUserAMonkey();
1156        } catch (RemoteException e) {
1157        }
1158        return false;
1159    }
1160
1161    /**
1162     * Returns "true" if device is running in a test harness.
1163     */
1164    public static boolean isRunningInTestHarness() {
1165        return SystemProperties.getBoolean("ro.test_harness", false);
1166    }
1167}
1168