ActivityManager.java revision f7f5dda5e54da53b98f1504672a422a484496531
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.heapsize", "16m");
68        return Integer.parseInt(vmHeapSize.substring(0, vmHeapSize.length()-1));
69    }
70
71    /**
72     * Information you can retrieve about tasks that the user has most recently
73     * started or visited.
74     */
75    public static class RecentTaskInfo implements Parcelable {
76        /**
77         * If this task is currently running, this is the identifier for it.
78         * If it is not running, this will be -1.
79         */
80        public int id;
81
82        /**
83         * The original Intent used to launch the task.  You can use this
84         * Intent to re-launch the task (if it is no longer running) or bring
85         * the current task to the front.
86         */
87        public Intent baseIntent;
88
89        /**
90         * If this task was started from an alias, this is the actual
91         * activity component that was initially started; the component of
92         * the baseIntent in this case is the name of the actual activity
93         * implementation that the alias referred to.  Otherwise, this is null.
94         */
95        public ComponentName origActivity;
96
97        public RecentTaskInfo() {
98        }
99
100        public int describeContents() {
101            return 0;
102        }
103
104        public void writeToParcel(Parcel dest, int flags) {
105            dest.writeInt(id);
106            if (baseIntent != null) {
107                dest.writeInt(1);
108                baseIntent.writeToParcel(dest, 0);
109            } else {
110                dest.writeInt(0);
111            }
112            ComponentName.writeToParcel(origActivity, dest);
113        }
114
115        public void readFromParcel(Parcel source) {
116            id = source.readInt();
117            if (source.readInt() != 0) {
118                baseIntent = Intent.CREATOR.createFromParcel(source);
119            } else {
120                baseIntent = null;
121            }
122            origActivity = ComponentName.readFromParcel(source);
123        }
124
125        public static final Creator<RecentTaskInfo> CREATOR
126                = new Creator<RecentTaskInfo>() {
127            public RecentTaskInfo createFromParcel(Parcel source) {
128                return new RecentTaskInfo(source);
129            }
130            public RecentTaskInfo[] newArray(int size) {
131                return new RecentTaskInfo[size];
132            }
133        };
134
135        private RecentTaskInfo(Parcel source) {
136            readFromParcel(source);
137        }
138    }
139
140    /**
141     * Flag for use with {@link #getRecentTasks}: return all tasks, even those
142     * that have set their
143     * {@link android.content.Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} flag.
144     */
145    public static final int RECENT_WITH_EXCLUDED = 0x0001;
146
147    /**
148     * Return a list of the tasks that the user has recently launched, with
149     * the most recent being first and older ones after in order.
150     *
151     * @param maxNum The maximum number of entries to return in the list.  The
152     * actual number returned may be smaller, depending on how many tasks the
153     * user has started and the maximum number the system can remember.
154     *
155     * @return Returns a list of RecentTaskInfo records describing each of
156     * the recent tasks.
157     *
158     * @throws SecurityException Throws SecurityException if the caller does
159     * not hold the {@link android.Manifest.permission#GET_TASKS} permission.
160     */
161    public List<RecentTaskInfo> getRecentTasks(int maxNum, int flags)
162            throws SecurityException {
163        try {
164            return ActivityManagerNative.getDefault().getRecentTasks(maxNum,
165                    flags);
166        } catch (RemoteException e) {
167            // System dead, we will be dead too soon!
168            return null;
169        }
170    }
171
172    /**
173     * Information you can retrieve about a particular task that is currently
174     * "running" in the system.  Note that a running task does not mean the
175     * given task actual has a process it is actively running in; it simply
176     * means that the user has gone to it and never closed it, but currently
177     * the system may have killed its process and is only holding on to its
178     * last state in order to restart it when the user returns.
179     */
180    public static class RunningTaskInfo implements Parcelable {
181        /**
182         * A unique identifier for this task.
183         */
184        public int id;
185
186        /**
187         * The component launched as the first activity in the task.  This can
188         * be considered the "application" of this task.
189         */
190        public ComponentName baseActivity;
191
192        /**
193         * The activity component at the top of the history stack of the task.
194         * This is what the user is currently doing.
195         */
196        public ComponentName topActivity;
197
198        /**
199         * Thumbnail representation of the task's current state.
200         */
201        public Bitmap thumbnail;
202
203        /**
204         * Description of the task's current state.
205         */
206        public CharSequence description;
207
208        /**
209         * Number of activities in this task.
210         */
211        public int numActivities;
212
213        /**
214         * Number of activities that are currently running (not stopped
215         * and persisted) in this task.
216         */
217        public int numRunning;
218
219        public RunningTaskInfo() {
220        }
221
222        public int describeContents() {
223            return 0;
224        }
225
226        public void writeToParcel(Parcel dest, int flags) {
227            dest.writeInt(id);
228            ComponentName.writeToParcel(baseActivity, dest);
229            ComponentName.writeToParcel(topActivity, dest);
230            if (thumbnail != null) {
231                dest.writeInt(1);
232                thumbnail.writeToParcel(dest, 0);
233            } else {
234                dest.writeInt(0);
235            }
236            TextUtils.writeToParcel(description, dest,
237                    Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
238            dest.writeInt(numActivities);
239            dest.writeInt(numRunning);
240        }
241
242        public void readFromParcel(Parcel source) {
243            id = source.readInt();
244            baseActivity = ComponentName.readFromParcel(source);
245            topActivity = ComponentName.readFromParcel(source);
246            if (source.readInt() != 0) {
247                thumbnail = Bitmap.CREATOR.createFromParcel(source);
248            } else {
249                thumbnail = null;
250            }
251            description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
252            numActivities = source.readInt();
253            numRunning = source.readInt();
254        }
255
256        public static final Creator<RunningTaskInfo> CREATOR = new Creator<RunningTaskInfo>() {
257            public RunningTaskInfo createFromParcel(Parcel source) {
258                return new RunningTaskInfo(source);
259            }
260            public RunningTaskInfo[] newArray(int size) {
261                return new RunningTaskInfo[size];
262            }
263        };
264
265        private RunningTaskInfo(Parcel source) {
266            readFromParcel(source);
267        }
268    }
269
270    /**
271     * Return a list of the tasks that are currently running, with
272     * the most recent being first and older ones after in order.  Note that
273     * "running" does not mean any of the task's code is currently loaded or
274     * activity -- the task may have been frozen by the system, so that it
275     * can be restarted in its previous state when next brought to the
276     * foreground.
277     *
278     * @param maxNum The maximum number of entries to return in the list.  The
279     * actual number returned may be smaller, depending on how many tasks the
280     * user has started.
281     *
282     * @return Returns a list of RunningTaskInfo records describing each of
283     * the running tasks.
284     *
285     * @throws SecurityException Throws SecurityException if the caller does
286     * not hold the {@link android.Manifest.permission#GET_TASKS} permission.
287     */
288    public List<RunningTaskInfo> getRunningTasks(int maxNum)
289            throws SecurityException {
290        try {
291            return (List<RunningTaskInfo>)ActivityManagerNative.getDefault()
292                    .getTasks(maxNum, 0, null);
293        } catch (RemoteException e) {
294            // System dead, we will be dead too soon!
295            return null;
296        }
297    }
298
299    /**
300     * Information you can retrieve about a particular Service that is
301     * currently running in the system.
302     */
303    public static class RunningServiceInfo implements Parcelable {
304        /**
305         * The service component.
306         */
307        public ComponentName service;
308
309        /**
310         * If non-zero, this is the process the service is running in.
311         */
312        public int pid;
313
314        /**
315         * The UID that owns this service.
316         */
317        public int uid;
318
319        /**
320         * The name of the process this service runs in.
321         */
322        public String process;
323
324        /**
325         * Set to true if the service has asked to run as a foreground process.
326         */
327        public boolean foreground;
328
329        /**
330         * The time when the service was first made active, either by someone
331         * starting or binding to it.
332         */
333        public long activeSince;
334
335        /**
336         * Set to true if this service has been explicitly started.
337         */
338        public boolean started;
339
340        /**
341         * Number of clients connected to the service.
342         */
343        public int clientCount;
344
345        /**
346         * Number of times the service's process has crashed while the service
347         * is running.
348         */
349        public int crashCount;
350
351        /**
352         * The time when there was last activity in the service (either
353         * explicit requests to start it or clients binding to it).
354         */
355        public long lastActivityTime;
356
357        /**
358         * If non-zero, this service is not currently running, but scheduled to
359         * restart at the given time.
360         */
361        public long restarting;
362
363        /**
364         * Bit for {@link #flags}: set if this service has been
365         * explicitly started.
366         */
367        public static final int FLAG_STARTED = 1<<0;
368
369        /**
370         * Bit for {@link #flags}: set if the service has asked to
371         * run as a foreground process.
372         */
373        public static final int FLAG_FOREGROUND = 1<<1;
374
375        /**
376         * Bit for {@link #flags): set if the service is running in a
377         * core system process.
378         */
379        public static final int FLAG_SYSTEM_PROCESS = 1<<2;
380
381        /**
382         * Bit for {@link #flags): set if the service is running in a
383         * persistent process.
384         */
385        public static final int FLAG_PERSISTENT_PROCESS = 1<<3;
386
387        /**
388         * Running flags.
389         */
390        public int flags;
391
392        /**
393         * For special services that are bound to by system code, this is
394         * the package that holds the binding.
395         */
396        public String clientPackage;
397
398        /**
399         * For special services that are bound to by system code, this is
400         * a string resource providing a user-visible label for who the
401         * client is.
402         */
403        public int clientLabel;
404
405        public RunningServiceInfo() {
406        }
407
408        public int describeContents() {
409            return 0;
410        }
411
412        public void writeToParcel(Parcel dest, int flags) {
413            ComponentName.writeToParcel(service, dest);
414            dest.writeInt(pid);
415            dest.writeInt(uid);
416            dest.writeString(process);
417            dest.writeInt(foreground ? 1 : 0);
418            dest.writeLong(activeSince);
419            dest.writeInt(started ? 1 : 0);
420            dest.writeInt(clientCount);
421            dest.writeInt(crashCount);
422            dest.writeLong(lastActivityTime);
423            dest.writeLong(restarting);
424            dest.writeInt(this.flags);
425            dest.writeString(clientPackage);
426            dest.writeInt(clientLabel);
427        }
428
429        public void readFromParcel(Parcel source) {
430            service = ComponentName.readFromParcel(source);
431            pid = source.readInt();
432            uid = source.readInt();
433            process = source.readString();
434            foreground = source.readInt() != 0;
435            activeSince = source.readLong();
436            started = source.readInt() != 0;
437            clientCount = source.readInt();
438            crashCount = source.readInt();
439            lastActivityTime = source.readLong();
440            restarting = source.readLong();
441            flags = source.readInt();
442            clientPackage = source.readString();
443            clientLabel = source.readInt();
444        }
445
446        public static final Creator<RunningServiceInfo> CREATOR = new Creator<RunningServiceInfo>() {
447            public RunningServiceInfo createFromParcel(Parcel source) {
448                return new RunningServiceInfo(source);
449            }
450            public RunningServiceInfo[] newArray(int size) {
451                return new RunningServiceInfo[size];
452            }
453        };
454
455        private RunningServiceInfo(Parcel source) {
456            readFromParcel(source);
457        }
458    }
459
460    /**
461     * Return a list of the services that are currently running.
462     *
463     * @param maxNum The maximum number of entries to return in the list.  The
464     * actual number returned may be smaller, depending on how many services
465     * are running.
466     *
467     * @return Returns a list of RunningServiceInfo records describing each of
468     * the running tasks.
469     */
470    public List<RunningServiceInfo> getRunningServices(int maxNum)
471            throws SecurityException {
472        try {
473            return (List<RunningServiceInfo>)ActivityManagerNative.getDefault()
474                    .getServices(maxNum, 0);
475        } catch (RemoteException e) {
476            // System dead, we will be dead too soon!
477            return null;
478        }
479    }
480
481    /**
482     * Returns a PendingIntent you can start to show a control panel for the
483     * given running service.  If the service does not have a control panel,
484     * null is returned.
485     */
486    public PendingIntent getRunningServiceControlPanel(ComponentName service)
487            throws SecurityException {
488        try {
489            return ActivityManagerNative.getDefault()
490                    .getRunningServiceControlPanel(service);
491        } catch (RemoteException e) {
492            // System dead, we will be dead too soon!
493            return null;
494        }
495    }
496
497    /**
498     * Information you can retrieve about the available memory through
499     * {@link ActivityManager#getMemoryInfo}.
500     */
501    public static class MemoryInfo implements Parcelable {
502        /**
503         * The total available memory on the system.  This number should not
504         * be considered absolute: due to the nature of the kernel, a significant
505         * portion of this memory is actually in use and needed for the overall
506         * system to run well.
507         */
508        public long availMem;
509
510        /**
511         * The threshold of {@link #availMem} at which we consider memory to be
512         * low and start killing background services and other non-extraneous
513         * processes.
514         */
515        public long threshold;
516
517        /**
518         * Set to true if the system considers itself to currently be in a low
519         * memory situation.
520         */
521        public boolean lowMemory;
522
523        public MemoryInfo() {
524        }
525
526        public int describeContents() {
527            return 0;
528        }
529
530        public void writeToParcel(Parcel dest, int flags) {
531            dest.writeLong(availMem);
532            dest.writeLong(threshold);
533            dest.writeInt(lowMemory ? 1 : 0);
534        }
535
536        public void readFromParcel(Parcel source) {
537            availMem = source.readLong();
538            threshold = source.readLong();
539            lowMemory = source.readInt() != 0;
540        }
541
542        public static final Creator<MemoryInfo> CREATOR
543                = new Creator<MemoryInfo>() {
544            public MemoryInfo createFromParcel(Parcel source) {
545                return new MemoryInfo(source);
546            }
547            public MemoryInfo[] newArray(int size) {
548                return new MemoryInfo[size];
549            }
550        };
551
552        private MemoryInfo(Parcel source) {
553            readFromParcel(source);
554        }
555    }
556
557    public void getMemoryInfo(MemoryInfo outInfo) {
558        try {
559            ActivityManagerNative.getDefault().getMemoryInfo(outInfo);
560        } catch (RemoteException e) {
561        }
562    }
563
564    /**
565     * @hide
566     */
567    public boolean clearApplicationUserData(String packageName, IPackageDataObserver observer) {
568        try {
569            return ActivityManagerNative.getDefault().clearApplicationUserData(packageName,
570                    observer);
571        } catch (RemoteException e) {
572            return false;
573        }
574    }
575
576    /**
577     * Information you can retrieve about any processes that are in an error condition.
578     */
579    public static class ProcessErrorStateInfo implements Parcelable {
580        /**
581         * Condition codes
582         */
583        public static final int NO_ERROR = 0;
584        public static final int CRASHED = 1;
585        public static final int NOT_RESPONDING = 2;
586
587        /**
588         * The condition that the process is in.
589         */
590        public int condition;
591
592        /**
593         * The process name in which the crash or error occurred.
594         */
595        public String processName;
596
597        /**
598         * The pid of this process; 0 if none
599         */
600        public int pid;
601
602        /**
603         * The kernel user-ID that has been assigned to this process;
604         * currently this is not a unique ID (multiple applications can have
605         * the same uid).
606         */
607        public int uid;
608
609        /**
610         * The activity name associated with the error, if known.  May be null.
611         */
612        public String tag;
613
614        /**
615         * A short message describing the error condition.
616         */
617        public String shortMsg;
618
619        /**
620         * A long message describing the error condition.
621         */
622        public String longMsg;
623
624        /**
625         * The stack trace where the error originated.  May be null.
626         */
627        public String stackTrace;
628
629        /**
630         * to be deprecated: This value will always be null.
631         */
632        public byte[] crashData = null;
633
634        public ProcessErrorStateInfo() {
635        }
636
637        public int describeContents() {
638            return 0;
639        }
640
641        public void writeToParcel(Parcel dest, int flags) {
642            dest.writeInt(condition);
643            dest.writeString(processName);
644            dest.writeInt(pid);
645            dest.writeInt(uid);
646            dest.writeString(tag);
647            dest.writeString(shortMsg);
648            dest.writeString(longMsg);
649            dest.writeString(stackTrace);
650        }
651
652        public void readFromParcel(Parcel source) {
653            condition = source.readInt();
654            processName = source.readString();
655            pid = source.readInt();
656            uid = source.readInt();
657            tag = source.readString();
658            shortMsg = source.readString();
659            longMsg = source.readString();
660            stackTrace = source.readString();
661        }
662
663        public static final Creator<ProcessErrorStateInfo> CREATOR =
664                new Creator<ProcessErrorStateInfo>() {
665            public ProcessErrorStateInfo createFromParcel(Parcel source) {
666                return new ProcessErrorStateInfo(source);
667            }
668            public ProcessErrorStateInfo[] newArray(int size) {
669                return new ProcessErrorStateInfo[size];
670            }
671        };
672
673        private ProcessErrorStateInfo(Parcel source) {
674            readFromParcel(source);
675        }
676    }
677
678    /**
679     * Returns a list of any processes that are currently in an error condition.  The result
680     * will be null if all processes are running properly at this time.
681     *
682     * @return Returns a list of ProcessErrorStateInfo records, or null if there are no
683     * current error conditions (it will not return an empty list).  This list ordering is not
684     * specified.
685     */
686    public List<ProcessErrorStateInfo> getProcessesInErrorState() {
687        try {
688            return ActivityManagerNative.getDefault().getProcessesInErrorState();
689        } catch (RemoteException e) {
690            return null;
691        }
692    }
693
694    /**
695     * Information you can retrieve about a running process.
696     */
697    public static class RunningAppProcessInfo implements Parcelable {
698        /**
699         * The name of the process that this object is associated with
700         */
701        public String processName;
702
703        /**
704         * The pid of this process; 0 if none
705         */
706        public int pid;
707
708        /**
709         * The user id of this process.
710         */
711        public int uid;
712
713        public String pkgList[];
714
715        /**
716         * Constant for {@link #importance}: this process is running the
717         * foreground UI.
718         */
719        public static final int IMPORTANCE_FOREGROUND = 100;
720
721        /**
722         * Constant for {@link #importance}: this process is running something
723         * that is considered to be actively visible to the user.
724         */
725        public static final int IMPORTANCE_VISIBLE = 200;
726
727        /**
728         * Constant for {@link #importance}: this process is contains services
729         * that should remain running.
730         */
731        public static final int IMPORTANCE_SERVICE = 300;
732
733        /**
734         * Constant for {@link #importance}: this process process contains
735         * background code that is expendable.
736         */
737        public static final int IMPORTANCE_BACKGROUND = 400;
738
739        /**
740         * Constant for {@link #importance}: this process is empty of any
741         * actively running code.
742         */
743        public static final int IMPORTANCE_EMPTY = 500;
744
745        /**
746         * The relative importance level that the system places on this
747         * process.  May be one of {@link #IMPORTANCE_FOREGROUND},
748         * {@link #IMPORTANCE_VISIBLE}, {@link #IMPORTANCE_SERVICE},
749         * {@link #IMPORTANCE_BACKGROUND}, or {@link #IMPORTANCE_EMPTY}.  These
750         * constants are numbered so that "more important" values are always
751         * smaller than "less important" values.
752         */
753        public int importance;
754
755        /**
756         * An additional ordering within a particular {@link #importance}
757         * category, providing finer-grained information about the relative
758         * utility of processes within a category.  This number means nothing
759         * except that a smaller values are more recently used (and thus
760         * more important).  Currently an LRU value is only maintained for
761         * the {@link #IMPORTANCE_BACKGROUND} category, though others may
762         * be maintained in the future.
763         */
764        public int lru;
765
766        /**
767         * Constant for {@link #importanceReasonCode}: nothing special has
768         * been specified for the reason for this level.
769         */
770        public static final int REASON_UNKNOWN = 0;
771
772        /**
773         * Constant for {@link #importanceReasonCode}: one of the application's
774         * content providers is being used by another process.  The pid of
775         * the client process is in {@link #importanceReasonPid} and the
776         * target provider in this process is in
777         * {@link #importanceReasonComponent}.
778         */
779        public static final int REASON_PROVIDER_IN_USE = 1;
780
781        /**
782         * Constant for {@link #importanceReasonCode}: one of the application's
783         * content providers is being used by another process.  The pid of
784         * the client process is in {@link #importanceReasonPid} and the
785         * target provider in this process is in
786         * {@link #importanceReasonComponent}.
787         */
788        public static final int REASON_SERVICE_IN_USE = 2;
789
790        /**
791         * The reason for {@link #importance}, if any.
792         */
793        public int importanceReasonCode;
794
795        /**
796         * For the specified values of {@link #importanceReasonCode}, this
797         * is the process ID of the other process that is a client of this
798         * process.  This will be 0 if no other process is using this one.
799         */
800        public int importanceReasonPid;
801
802        /**
803         * For the specified values of {@link #importanceReasonCode}, this
804         * is the name of the component that is being used in this process.
805         */
806        public ComponentName importanceReasonComponent;
807
808        public RunningAppProcessInfo() {
809            importance = IMPORTANCE_FOREGROUND;
810            importanceReasonCode = REASON_UNKNOWN;
811        }
812
813        public RunningAppProcessInfo(String pProcessName, int pPid, String pArr[]) {
814            processName = pProcessName;
815            pid = pPid;
816            pkgList = pArr;
817        }
818
819        public int describeContents() {
820            return 0;
821        }
822
823        public void writeToParcel(Parcel dest, int flags) {
824            dest.writeString(processName);
825            dest.writeInt(pid);
826            dest.writeInt(uid);
827            dest.writeStringArray(pkgList);
828            dest.writeInt(importance);
829            dest.writeInt(lru);
830            dest.writeInt(importanceReasonCode);
831            dest.writeInt(importanceReasonPid);
832            ComponentName.writeToParcel(importanceReasonComponent, dest);
833        }
834
835        public void readFromParcel(Parcel source) {
836            processName = source.readString();
837            pid = source.readInt();
838            uid = source.readInt();
839            pkgList = source.readStringArray();
840            importance = source.readInt();
841            lru = source.readInt();
842            importanceReasonCode = source.readInt();
843            importanceReasonPid = source.readInt();
844            importanceReasonComponent = ComponentName.readFromParcel(source);
845        }
846
847        public static final Creator<RunningAppProcessInfo> CREATOR =
848            new Creator<RunningAppProcessInfo>() {
849            public RunningAppProcessInfo createFromParcel(Parcel source) {
850                return new RunningAppProcessInfo(source);
851            }
852            public RunningAppProcessInfo[] newArray(int size) {
853                return new RunningAppProcessInfo[size];
854            }
855        };
856
857        private RunningAppProcessInfo(Parcel source) {
858            readFromParcel(source);
859        }
860    }
861
862    /**
863     * Returns a list of application processes installed on external media
864     * that are running on the device.
865     *
866     * @return Returns a list of ApplicationInfo records, or null if none
867     * This list ordering is not specified.
868     * @hide
869     */
870    public List<ApplicationInfo> getRunningExternalApplications() {
871        try {
872            return ActivityManagerNative.getDefault().getRunningExternalApplications();
873        } catch (RemoteException e) {
874            return null;
875        }
876    }
877
878    /**
879     * Returns a list of application processes that are running on the device.
880     *
881     * @return Returns a list of RunningAppProcessInfo records, or null if there are no
882     * running processes (it will not return an empty list).  This list ordering is not
883     * specified.
884     */
885    public List<RunningAppProcessInfo> getRunningAppProcesses() {
886        try {
887            return ActivityManagerNative.getDefault().getRunningAppProcesses();
888        } catch (RemoteException e) {
889            return null;
890        }
891    }
892
893    /**
894     * Return information about the memory usage of one or more processes.
895     *
896     * @param pids The pids of the processes whose memory usage is to be
897     * retrieved.
898     * @return Returns an array of memory information, one for each
899     * requested pid.
900     */
901    public Debug.MemoryInfo[] getProcessMemoryInfo(int[] pids) {
902        try {
903            return ActivityManagerNative.getDefault().getProcessMemoryInfo(pids);
904        } catch (RemoteException e) {
905            return null;
906        }
907    }
908
909    /**
910     * @deprecated This is now just a wrapper for
911     * {@link #killBackgroundProcesses(String)}; the previous behavior here
912     * is no longer available to applications because it allows them to
913     * break other applications by removing their alarms, stopping their
914     * services, etc.
915     */
916    @Deprecated
917    public void restartPackage(String packageName) {
918        killBackgroundProcesses(packageName);
919    }
920
921    /**
922     * Have the system immediately kill all background processes associated
923     * with the given package.  This is the same as the kernel killing those
924     * processes to reclaim memory; the system will take care of restarting
925     * these processes in the future as needed.
926     *
927     * <p>You must hold the permission
928     * {@link android.Manifest.permission#KILL_BACKGROUND_PROCESSES} to be able to
929     * call this method.
930     *
931     * @param packageName The name of the package whose processes are to
932     * be killed.
933     */
934    public void killBackgroundProcesses(String packageName) {
935        try {
936            ActivityManagerNative.getDefault().killBackgroundProcesses(packageName);
937        } catch (RemoteException e) {
938        }
939    }
940
941    /**
942     * Have the system perform a force stop of everything associated with
943     * the given application package.  All processes that share its uid
944     * will be killed, all services it has running stopped, all activities
945     * removed, etc.  In addition, a {@link Intent#ACTION_PACKAGE_RESTARTED}
946     * broadcast will be sent, so that any of its registered alarms can
947     * be stopped, notifications removed, etc.
948     *
949     * <p>You must hold the permission
950     * {@link android.Manifest.permission#FORCE_STOP_PACKAGES} to be able to
951     * call this method.
952     *
953     * @param packageName The name of the package to be stopped.
954     *
955     * @hide This is not available to third party applications due to
956     * it allowing them to break other applications by stopping their
957     * services, removing their alarms, etc.
958     */
959    public void forceStopPackage(String packageName) {
960        try {
961            ActivityManagerNative.getDefault().forceStopPackage(packageName);
962        } catch (RemoteException e) {
963        }
964    }
965
966    /**
967     * Get the device configuration attributes.
968     */
969    public ConfigurationInfo getDeviceConfigurationInfo() {
970        try {
971            return ActivityManagerNative.getDefault().getDeviceConfigurationInfo();
972        } catch (RemoteException e) {
973        }
974        return null;
975    }
976
977    /**
978     * Returns "true" if the user interface is currently being messed with
979     * by a monkey.
980     */
981    public static boolean isUserAMonkey() {
982        try {
983            return ActivityManagerNative.getDefault().isUserAMonkey();
984        } catch (RemoteException e) {
985        }
986        return false;
987    }
988}
989