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