Just An Application

May 22, 2012

Adventures In Distributed Garbage Collection: Part Eleven – Post Bind System Process State

Filed under: Android, Android Internals, Java, Mobile Java, Services — Tags: , , , , — Simon Lewis @ 6:00 am

1.0 Object State

As in the Service client and Service cases we can use the source code to derive a diagram which shows the Service related objects that should exist in the System process and their relationships after a client has bound to the Service.

2.0 dumpsys Output

We can use the output from the Android dumpsys command to check whether the ActivityManagerService is doing what we think it is when the client binds to the Fastnet Service.

Below are excerpts from the output of the dumpsys command run immediately after the client has successfully bound to the Fastnet Service.
In some cases the output has been slightly re-formatted for clarity.

2.1 ProcessRecords

2.1.1 Service Client ProcessRecord


    *APP* UID 10054 ProcessRecord{4067a100 293:xper.service.fastnet.client/10054}
      dir=/data/app/xper.service.fastnet.client-2.apk \
          publicDir=/data/app/xper.service.fastnet.client-2.apk data=/data/data/xper.service.fastnet.client
      thread=android.app.ApplicationThreadProxy@406c1890 curReceiver=null
      pid=293 starting=false lastPss=0
      lastActivityTime=-1m6s575ms lruWeight=253489 keeping=true hidden=false empty=false
      oom: max=15 hidden=7 curRaw=0 setRaw=0 cur=0 set=0
      curSchedGroup=0 setSchedGroup=0
      setIsForeground=false foregroundServices=false forcingToForeground=null
      persistent=false removed=false
      adjSeq=198 lruSeq=57
      lastRequestedGc=-1m6s576ms lastLowMemory=-1m6s576ms reportLowMemory=false
      activities=[HistoryRecord{407ad2d8 xper.service.fastnet.client/.FastnetClientActivity}]
      connections=[ConnectionRecord{40706ac0 xper.service.fastnet/.FastnetService:@40721f08}]
      conProviders={ContentProviderRecord{4051bc78 com.android.providers.settings.SettingsProvider}=1}

The ProcessRecord [0x4067a100] for the Service client process is present and has a reference to a single ConnectionRecord [0x40706ac0] as expected.

2.1.1 Service ProcessRecord


    *APP* UID 10053 ProcessRecord{4076e000 301:xper.service.fastnet/10053}
      dir=/data/app/xper.service.fastnet-2.apk \
          publicDir=/data/app/xper.service.fastnet-2.apk data=/data/data/xper.service.fastnet
      thread=android.app.ApplicationThreadProxy@4077e2a0 curReceiver=null
      pid=301 starting=false lastPss=0
      lastActivityTime=-59s120ms lruWeight=141059 keeping=true hidden=false empty=true
      oom: max=15 hidden=7 curRaw=0 setRaw=0 cur=0 set=0
      curSchedGroup=0 setSchedGroup=0
      setIsForeground=false foregroundServices=false forcingToForeground=null
      persistent=false removed=false
      adjSeq=198 lruSeq=60
      lastRequestedGc=-59s121ms lastLowMemory=-59s121ms reportLowMemory=false
      services=[ServiceRecord{406f89b8 xper.service.fastnet/.FastnetService}]

The ProcessRecord [0x4076e000] for the Service process is present and has a reference to a single ServiceRecord [0x406f89b8] as expected.

2.2 ActivityRecord

    Activities in Current Activity Manager State:
      * TaskRecord{4070aa90 #3 A xper.service.fastnet.client}
        clearOnBackground=false numActivities=1 rootWasReset=true
        intent={act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] \
            flg=0x10200000 cmp=xper.service.fastnet.client/.FastnetClientActivity bnds=[83,316][157,395]}
        lastActiveTime=253499 (inactive for 66s)
        * Hist #1: HistoryRecord{407ad2d8 xper.service.fastnet.client/.FastnetClientActivity}
            packageName=xper.service.fastnet.client processName=xper.service.fastnet.client
            launchedFromUid=10001 app=ProcessRecord{4067a100 293:xper.service.fastnet.client/10054}
            Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] \
                flg=0x10200000 cmp=xper.service.fastnet.client/.FastnetClientActivity bnds=[83,316][157,395] }
            frontOfTask=true task=TaskRecord{4070aa90 #3 A xper.service.fastnet.client}
            base=/data/app/xper.service.fastnet.client-2.apk/data/app/xper.service.fastnet.client-2.apk \
            labelRes=0x7f040001 icon=0x7f020000 theme=0x0
            stateNotNeeded=false componentSpecified=true isHomeActivity=false
            configuration={ scale=1.0 imsi=310/260 loc=en_US touch=3 keys=2/1/2 nav=3/1 orien=1 layout=18 uiMode=17 seq=4}
            launchFailed=false haveState=false icicle=null
            state=RESUMED stopped=false delayedResume=false finishing=false
            keysPaused=false inHistory=true launchMode=0
            fullscreen=true visible=true frozenBeforeDestroy=false thumbnailNeeded=false idle=true
            waitingVisible=false nowVisible=true
            connections=[ConnectionRecord{40706ac0 xper.service.fastnet/.FastnetService:@40721f08}]

The ActivityRecord [0x4070aa90] representing the Activity running in the Service client process has a reference to a ConnectionRecord
[0x40706ac0] as expected.


When printed an ActivityRecord identifies itself as a HistoryRecord for reasons best known to itself.

2.3 ServiceRecord


      * ServiceRecord{406f89b8 xper.service.fastnet/.FastnetService}
        app=ProcessRecord{4076e000 301:xper.service.fastnet/10053}
        createTime=-58s92ms lastActivity=-58s696ms
         executingStart=-58s690ms restartTime=-58s696ms
        * IntentBindRecord{40704020}:
          requested=true received=true hasBound=true doRebind=false
          * Client AppBindRecord{407040d0 ProcessRecord{4067a100 293:xper.service.fastnet.client/10054}}
            Per-process Connections:
              ConnectionRecord{40706ac0 xper.service.fastnet/.FastnetService:@40721f08}
        All Connections:
          ConnectionRecord{40706ac0 xper.service.fastnet/.FastnetService:@40721f08}

The ServiceRecord [0x406f89b8] representing the Fastnet Service is present and it references a single IntentBindRecord [0x4067a100] as expected.

The IntentBindRecord [0x4067a100] references a single AppBindRecord [0x407040d0] as expected.

The AppBindRecord [0x407040d0] references the ProcessRecord [0x4067a100] which represents the Fastnet Service client and has a single reference to a ConnectionRecord [0x40706ac0] as expected,

2.4 ConnectionRecord

    Connection bindings to services:
    * ConnectionRecord{40706ac0 xper.service.fastnet/.FastnetService:@40721f08}
      binding=AppBindRecord{407040d0 xper.service.fastnet/.FastnetService:xper.service.fastnet.client}
      activity=HistoryRecord{407ad2d8 xper.service.fastnet.client/.FastnetClientActivity}
      conn=android.os.BinderProxy@40721f08 flags=0x1

The ConnectionRecord [0x40706ac0] references the ActivityRecord [0x407040d0] for the FastnetClientActivity and the AppBindRecord [0x407040d0] as expected.

3.0 Java Heap State

In this case we already have the dumpsys output but we can, as in the Service client and Service cases, also use the state of the Java heap of the System process after the client has bound to the Fastnet Service to double-check.

As in the two previous case we can automatically generate a graph which shows the relationships between the objects in the heap.

This graph was generated using the ServiceRecord object [0x406f89b8] representing the Fastnet Service as the root.

The greyed out nodes have been filtered, that is, one or more instance variables have been omitted. This makes the graph only marginally less complicated in this case.

The complexity of the graph makes it difficult to see but it does confirm the output from dumpsys.

Copyright (c) 2012 By Simon Lewis. All Rights Reserved.


1 Comment »

  1. […] before we already have the dumpsys output, but again we can use the the state of the Java heap of the […]

    Pingback by Adventures In Dustributed Garbage Collection: Part Fifteen – Post Unbind System State « Just An Application — May 28, 2012 @ 8:41 am

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: