framework中的ProcessRecord

本文深入探讨了 Android 4.0 中的进程管理机制,详细介绍了 ProcessRecord 类的结构和作用,通过具体实例展示了不同组件如何在一个进程中协同工作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

android 4.0

1、

每个android进程,在AMS中对应有一个ProcessRecord
/**
 * Full information about a particular process that
 * is currently running.
 */
class ProcessRecord {

    final ApplicationInfo info; // all about the first app in the process  // 该进程中第一个驻留的app(apk)
    final String processName;   // name of the process
    // List of packages running in the process
    final HashSet<String> pkgList = new HashSet<String>();            // 该进程中可以驻留多个app(apk),可以对照下面bugreport中的日志
    
    int pid;                    // The process of this application;0 if none
    
    // contains HistoryRecord objects
    final ArrayList<ActivityRecord> activities = new ArrayList<ActivityRecord>();
    // all ServiceRecord running in this process
    final HashSet<ServiceRecord> services = new HashSet<ServiceRecord>();
    // services that are currently executing code (need to remain foreground).
    final HashSet<ServiceRecord> executingServices
             = new HashSet<ServiceRecord>();
    // All ConnectionRecord this process holds
    final HashSet<ConnectionRecord> connections
            = new HashSet<ConnectionRecord>();  
    // all IIntentReceivers that are registered from this process.
    final HashSet<ReceiverList> receivers = new HashSet<ReceiverList>();
    // class (String) -> ContentProviderRecord
    final HashMap<String, ContentProviderRecord> pubProviders
            = new HashMap<String, ContentProviderRecord>();
    // All ContentProviderRecord process is using
    final HashMap<ContentProviderRecord, Integer> conProviders
            = new HashMap<ContentProviderRecord, Integer>(); 

    void dump(PrintWriter pw, String prefix) { ......}
            
}

参考代码:http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.4.2_r1/com/android/server/am/ProcessRecord.java#ProcessRecord


2

2.1 比如android 4.0 源码中的某些app,配置在同一个process(com.android.phone)里面

/packages/apps/Phone/AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.android.phone"
        coreApp="true"
        android:sharedUserId="android.uid.phone"
        android:sharedUserLabel="@string/phoneAppLabel" >
        <application android:name="PhoneApp"
                 android:persistent="true"
                 android:label="@string/phoneAppLabel"
                 android:icon="@drawable/ic_launcher_phone">
                
/packages/providers/TelephonyProvider/AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.android.providers.telephony"
        coreApp="true"
        android:sharedUserId="android.uid.phone">
        <application android:process="com.android.phone"
                 android:allowClearUserData="false"
                 android:allowBackup="false"
                 android:label="@string/app_label"
                 android:icon="@drawable/ic_launcher_phone">


2.2、bugreport日志(使用adb shell bugreport > bugreport.txt抓取的日志,参照ProcessRecord中的dump方法看下面日志)

  *PERS* UID 1001 ProcessRecord{43a6db60 3480:com.android.phone/1001}

    user #0 uid=1001

    class=com.android.phone.PhoneApp     =》该进程中驻留的第一个app

    dir=/system/priv-app/TeleService.apk publicDir=/system/priv-app/TeleService.apk data=/data/data/com.android.phone     =》第一个app对应的信息

    packageList={com.android.providers.telephony, com.android.phone.recorder, com.android.stk, com.android.incallui,  com.android.phone}      =》该进程中驻留的package列表(apk列表)

    compat={480dpi}

    thread=android.app.ApplicationThreadProxy@439ef138

    pid=3480 starting=false

    lastActivityTime=-1h18m31s370ms lastPssTime=-2m48s884ms nextPssTime=+12m10s907ms

    adjSeq=88299 lruSeq=0 lastPss=36110 lastCachedPss=0

    keeping=true cached=false empty=false

    oom: max=-12 curRaw=-12 setRaw=-12 cur=-12 set=-12

    curSchedGroup=-1 setSchedGroup=-1 systemNoUi=true trimMemoryLevel=5

    curProcState=0 repProcState=0 pssProcState=0 setProcState=0 lastStateTime=-10h1m35s579ms

    hasShownUi=true pendingUiClean=false hasAboveClient=false

    persistent=true removed=false

    lastRequestedGc=-10h1m35s579ms lastLowMemory=-10h1m35s579ms reportLowMemory=false

    Activities:

      - ActivityRecord{43a614c8 u0 com.android.stk/.StkMenuActivity t3}

      - ActivityRecord{43dded98 u0 com.android.incallui/.MSimInCallActivity t5}

    Services:

      - ServiceRecord{43ab8000 u0 com.android.phone.recorder/.RecorderServer}

      - ServiceRecord{43ace900 u0 com.android.phone/.BluetoothPhoneService}

      - ServiceRecord{43c3e4b0 u0 com.android.phone/.TelephonyDebugService}

      - ServiceRecord{43ceda38 u0 com.android.incallui/.CallHandlerService}

      - ServiceRecord{43dcaab8 u0 com.android.stk/.StkAppService}

    Connections:

      - ConnectionRecord{439b55d8 u0 CR com.android.smspush/.WapPushManager:@439b7710}

      - ConnectionRecord{43a05ae0 u0 CR com.android.smspush/.WapPushManager:@43a99050}

      - ConnectionRecord{43a1d808 u0 com.android.bluetooth/.hfp.HeadsetService:@43cb3600}

      - ConnectionRecord{43aa7238 u0 com.android.bluetooth/.hfp.HeadsetService:@43aa7190}

      - ConnectionRecord{43af3ef8 u0 com.android.phone/.BluetoothPhoneService:@43beb818}

      - ConnectionRecord{43bf6f70 u0 CR com.android.smspush/.WapPushManager:@43af9f90}

      - ConnectionRecord{43bfc9d8 u0 CR com.android.phone.recorder/.RecorderServer:@43ab7ce8}

      - ConnectionRecord{43c18fc8 u0 CR com.android.smspush/.WapPushManager:@43c87940}

      - ConnectionRecord{43c1a138 u0 CR com.android.incallui/.CallHandlerService:@43ced788}

      - ConnectionRecord{43c64360 u0 com.android.bluetooth/.hfp.HeadsetService:@43c642b8}

    Published Providers:

      - com.android.providers.telephony.SmsProvider

        -> ContentProviderRecord{43a090e8 u0 com.android.providers.telephony/.SmsProvider}

      - com.android.stk.StkContentProvider

        -> ContentProviderRecord{439d1a40 u0 com.android.stk/.StkContentProvider}

     ......

    Connected Providers:

      - 436b3418/com.android.providers.settings/.SettingsProvider->3480:com.android.phone/1001 s1/1 u0/0 +23h10m54s283ms

    Receivers:

      - ReceiverList{439981f0 3480 com.android.phone/1001/u0 remote:43caace0}

      - ReceiverList{439b6f88 3480 com.android.phone/1001/u0 remote:439d2240}

      ......


参考:

http://blog.youkuaiyun.com/guoqifa29/article/details/39318585

http://blog.youkuaiyun.com/luoshengyang/article/details/6685853

http://www.blogjava.net/easywu/archive/2011/10/19/361554.html

http://blog.youkuaiyun.com/cigogo/article/details/7483676

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值