AMS系列③—常见的数据结构

2020-10-25  本文已影响0人  leap_

本文介绍AMS管理Activity时涉及到的重要的数据结构:

ProcessRecord

AMS中的ProcessRecord成员变量

变量 意义 注释
mProcessNames 数据类型为ProcessMap,以包名为key来记录ProcessRecord; All of the applications we currently have running organized by name.The keys are strings of the application package name (as returned by the package manager)
mPidsSelfLocked 数据类型为SparseArray,以进程pid为key来记录ProcessRecord All of the processes we currently have running organized by pid.
mLruProcesses 以Lru排序的ArrayList<ProcessRecord> List of running applications, sorted by recent usage.
mRemovedProcesses 数据类型为ArrayList,记录所有需要强制移除的进程; Processes that are being forcibly torn down.
mProcessesToGc 数据类型为ArrayList,记录系统进入idle状态需执行gc操作的进程; List of processes that should gc as soon as things are idle.
mPendingPssProcesses 数据类型为ArrayList,记录将要收集内存使用数据PSS的进程; Processes we want to collect PSS data from.
mProcessesOnHold 数据类型为ArrayList,记录刚开机过程,系统还没与偶准备就绪的情况下, 所有需要启动的进程都放入到该队列; List of records for processes that someone had tried to start before the system was ready. We don't start them at that point, but ensure they are started by the time booting is complete.
mPersistentStartingProcesses 数据类型ArrayList,正在启动的persistent进程 List of persistent applicationsthat are in the process of being started.
mHomeProcess 记录包含home Activity所在的进程;应该是Launcher进程吧,因为AMS开启的第一个activity有一个方法叫getHomeIntent,我猜的 This is the process holding what we currently consider to be the "home" activity.
mPreviousProcess 上一次访问的进程 This is the process holding the activity the user last visited that is in a different process from the one they are currently in.

因为每个人的翻译不一样,英文才能最准确的表达金毛的意思,所以我把注释贴出来给大家参考;最重要的是前三个加红的变量;

上面提到了进程的pss data,科普一下内存相关的知识:

一般来说内存占用大小有如下规律:VSS >= RSS >= PSS >= USS

persistent applications:

在manifest中配置的persistent属性,这个属性配置好了后会开机自启,在AMS的SystemReady中会开启所有的persistent为true的进程;

ProcessRecord中的成员变量

    int pid;                    // The process of this application; 0 if none
    final String processName;   // name of the process

    IApplicationThread thread;  // the actual proc...  may be null only if
                                // 'persistent' is true (in which case we
                                // are in the process of launching the app)

    int maxAdj;                 // Maximum OOM adjustment for this process
    int curRawAdj;              // Current OOM unlimited adjustment for this process
    int setRawAdj;              // Last set OOM unlimited adjustment for this process
    int curAdj;                 // Current OOM adjustment for this process
    int setAdj;                 // Last set OOM adjustment for this process
    int verifiedAdj;            // The last adjustment that was verified as actually being set

    // all activities running in the process
    final ArrayList<ActivityRecord> activities = new ArrayList<>();
    // any tasks this process had run root activities in
    final ArrayList<TaskRecord> recentTasks = new ArrayList<>();
    // all ServiceRecord running in this process
    final ArraySet<ServiceRecord> services = new ArraySet<>();
    // services that are currently executing code (need to remain foreground).
    final ArraySet<ServiceRecord> executingServices = new ArraySet<>();
    // All ConnectionRecord this process holds
    final ArraySet<ConnectionRecord> connections = new ArraySet<>();
    // all IIntentReceivers that are registered from this process.
    final ArraySet<ReceiverList> receivers = new ArraySet<>();
    // class (String) -> ContentProviderRecord
    final ArrayMap<String, ContentProviderRecord> pubProviders = new ArrayMap<>();
    // All ContentProviderRecord process is using
    final ArrayList<ContentProviderConnection> conProviders = new ArrayList<>();

    Dialog anrDialog;           // dialog being displayed due to app not resp.
    Dialog crashDialog;         // dialog being displayed due to crash.

    boolean killedByAm;         // True when proc has been killed by activity manager, not for RAM

ActivityRecord

在AMS中,活动是以ActivityRecord的形式记录的,由ActivityStarter创建,关于ActivityStarter会在后面的文章中介绍,先看一下ActivityRecord记录了哪些数据:

    final ActivityManagerService service; // owner
    final Intent intent;    // the original intent that generated us
    final ActivityInfo info; // all about me 
    ProcessRecord app;      // if non-null, hosting application
    private TaskRecord task;        // the task this is in.
    final String launchedFromPackage; // always the package who started the activity.
    final String taskAffinity; // as per ActivityInfo.taskAffinity
    final ActivityStackSupervisor mStackSupervisor;
    int launchMode;         // the launch mode activity attribute.
    private ActivityState mState;    // current state we are in

TaskRecord

    final int taskId;       // Unique identifier for this task.
    String affinity;        // The affinity name for this task, or null; may change identity.
    Intent intent;          // The original intent that started the task.
    /** List of all activities in the task arranged in history order */
    final ArrayList<ActivityRecord> mActivities;
    /** Current stack. Setter must always be used to update the value. */
    private ActivityStack mStack;
    final ActivityManagerService mService;

TaskRecord存储了任务栈的所有信息,包括当前栈的活动List,栈的affinity属性,以及对应ActivityStack对象,下篇会详细介绍ActivityStack以及AMS家族其他的成员;

上一篇 下一篇

猜你喜欢

热点阅读