Just An Application

May 15, 2012

Adventures In Distributed Garbage Collection: Part Four – The Cast Of Characters Continued: Objects And Actor State

1.0 Process: SystemServer

1.1 Objects

1.1.1 ProcessRecord

Package: com.android.server.am

Source: frameworks/base/services/java/com/android/server/am/ProcessRecord.java

A ProcessRecord object represents a process which is running at least one Android application.

The ActivityManagerService holds a ProcessRecord object for each such process.

1.1.1.1 Instance Variables: Service Related State

1.1.1.1.1 thread

Type: IApplicationThread

A proxy object for the ApplicationThread in the corresponding process.

1.1.1.1.2 services

Type: HashSet<ServiceRecord>

A set containing the ServiceRecord for each Service running in the corresponding process,

1.1.1.1.3 executingServices

Type: HashSet<ServiceRecord>

A set containing the ServiceRecord for each Service in the corresponding process which is currently executing an action requested by the
ActivityManagerService.

1.1.1.1.4 connections

Type: HashSet<ConnectionRecord>

A set containing the ConnectionRecord for each connection to a Service from the corresponding process

1.1.2 ActivityRecord

Package: com.android.server.am

Source: frameworks/base/services/java/com/android/server/am/ActivityRecord.java

An ActivityRecord object represents an Activity in an Android Application process.

1.1.2.1 Instance Variables: Service Related State

1.1.2.1.1 connections

Type: HashSet<ConnectionRecord>

A set containing the ConnectionRecord for each existing connection to a Service which was created by the Activity
represented by this ActivityRecord

1.1.3 ServiceRecord

Package: com.android.server.am

Source: frameworks/base/services/java/com/android/server/am/ServiceRecord.java

A ServiceRecord object represents a Service Component in an Android Application process.

1.1.3.1 Instance Variables

1.1.3.1.1 bindings

Type: HashMap<Intent.FilterComparison, IntentBindRecord>

The set of all Intent/IBinder bindings established by the Service.

1.1.3.1.2 connections

Type: HashMap<IBinder, ArrayList<ConnectionRecord>>

The set of all connections to the Service.

The connections are held in a map indexed by the IServiceConnection object used to interact with them.

As the same IServiceConnection object may be associated with multiple connections each entry in the map is a
ConnectionRecord list.

1.1.3.1.3 app

Type: ProcessRecord

The ProcessRecord which represents the process in which the Service component is running.

1.1.4 IntentBindRecord

Package: com.android.server.am

Source: frameworks/base/services/java/com/android/server/am/IntentBindRecord.java

An IntentBindRecord object represents the binding between an Intent and an IBinder object for a given Service.

1.1.4.1 Instance Variables

1.1.4.1.1 service

Type: ServiceRecord

The ServiceRecord which represents the Service that created the binding.

1.1.4.1.2 intent

Type: Intent.FilterComparison

The Intent which identifies this binding.

1.1.4.1.2 binder

Type: IBinder

The IBinder object which will be returned to a client binding to the given Service using the associated Intent.

1.1.4.1.3 apps

Type: HashMap<ProcessRecord, AppBindRecord>

The set of connections which are uisng this binding.

1.1.4.1.4 requested

Type: boolean

true if the Service has been requested to provide an IBinder object for the given Intent.

1.1.4.1.5 received

Type: boolean

true if an IBinder object for the given Intent has been received from the Service.

1.1.4.1.6 hasBound

Type: boolean

true if a client has requested a binding to the Service using the associated Intent.

1.1.4.1.7 doRebind

Type: boolean

true if there are currently no Service clients using this binding and the Service should be notified when a new client binds to the Service using the associated Intent.

1.1.5 AppBindRecord

Package: com.android.server.am

Source: frameworks/base/services/java/com/android/server/am/AppBindRecord.java

An AppBindRecord object represents the set of connections to a single Service that were created by the same Process and which use the same
Intent/IBinder binding.

1.1.5.1 Instance Variables

1.1.5.1.1 service

Type: ServiceRecord

The ServiceRecord which represents the Service the connections are connected to.

1.1.5.1.2 intent

Type: IntentBindRecord

The Intent/IBinder binding being used by the connections.

1.1.5.1.3 client

Type: ProcessRecord

The ProcessRecord which represents the process that created the connections.

1.1.5.1.4 connections

Type: HashSet<ConnectionRecord>

A set containing the ConnectionRecord for each connection created by the associated Process.

1.1.6 ConnectionRecord

Package: com.android.server.am

Source: frameworks/base/services/java/com/android/server/am/ConnectionRecord.java

A ConnectionRecord object represents a connection to a Service.

1.1.6.1 Instance Variables

1.1.6.1.1 activity

Type: ActivityRecord

The ActivityRecord which represents the Activity, if any, which created the connection.

1.1.6.1.2 binding

Type: AppBindRecord

The connection context. Indirectly this specifies

1.1.6.1.3 conn

Type: IServiceConnection

The IServiceConnection object to use for status change notifications.

1.1.6.1.4 flags

Type: int

The set of bit-flags specified when the connection was created.

1.1.7 Intent.FilterComparison

Package: android.content

Source: frameworks/base/core/java/android/content/Intent.java

The FilterComparison class is a static inner-class contained within the class android.content.Intent.

A FilterComparison instance is used to wrap an instance of android.content.Intent.

It overrides the method

   public boolean equals(Object obj)

with an implementation that uses the method Intent.filterEquals(Intent other).

FilterComparison instances are frequently used as keys in maps.

1.2 Actor State

1.2.1 ActivityServiceManager: Service Related State

1.2.1.1 Instance Variables

1.2.1.1.1 mServices

Type: HashMap<ComponentName, ServiceRecord>

The ServiceRecords for all active Services indexed by the name of the Service Component.

1.2.1.1.3 mServicesByIntent

Type: HashMap<Intent.FilterComparison, ServiceRecord>

The ServiceRecords for all active Services indexed by the Intent which was used to access them.

1.2.1.1.3 mPendingServices

Type: ArrayList<ServiceRecord>

A list of the ServiceRecords of all Services that are currently waiting to be started by the ActivityManagerService.

1.2.1.1.3 mStoppingServices

Type: ArrayList<ServiceRecord>

A list of the ServiceRecords of all Services that are currently being stopped by the ActivityManagerService.

1.2.1.1.3 mServiceConnections

Type: HashMap<IBinder, ArrayList<ConnectionRecord>>

The ConnectionRecords for all Service connections indexed by the IServiceConnection object associated with the connection.

1.3 Class Relationship Diagram

2.0 Process: Service

2.1 Actor State

2.1.1 ActivityThread: Service Related State

2.1.1.1 Instance Variables

2.1.1.1.1 mServices

Type: HashMap<IBinder, Service>

The set of Service Components in the Android application process managed by this ActivityThread.

2.1.2 Service Component

2.1.2.1 Service: Instance Variables

2.1.2.1.1 mToken

Type: IBinder

An IBinder object which is used to identify the Service Component in interactions with the ActivityManagerService.

2.2 Class Relationship Diagram

3.0 Process: Service Client

3.1 Objects

3.1.1 ContextImpl

Package: android.app

Source: frameworks/base/core/java/android/app/ContextImpl.java

The ContextImpl class is a sub-class of the abstract class android.content.Context.

The ContextImpl class implements the interface to the Android Application runtime available to Android Application Components defined by the android.content.Context class.

Android Application components such as Activities and Services hold a reference to a ContextImpl object to which they delegate all Context defined method calls.

3.1.1.1 Instance Variables

3.1.1.1.1 mPackageInfo

Type: LoadedApk

Apk state for this Context.

3.1.2 LoadedApk

Package: android.app

Source: frameworks/base/core/java/android/app/LoadedApk.java

A LoadedApk object represents the state of the Components defined in an Android .apk that has been loaded into an Android process.

3.2.1 Instance Variables

3.2.1.1 mServices

Type: HashMap<Context, HashMap<ServiceConnection, LoadedApk.ServiceDispatcher>>

A map from ServiceConnection objects to the ServiceDispatcher objects responsible for them

3.1.3 LoadedApk.ServiceDispatcher

Package: android.app

Source: frameworks/base/core/java/android/app/LoadedApk.java

Definition: 896-1106

A ServiceDispatcher object is created for each distinct object implementing the ServiceConnection interface which is used when binding to a Service in a given Context.

The resulting ServiceDispatcher object is responsible for managing all the connections to Services which result from binding to them using the associated ServiceConnection object.

It interacts with its associated ServiceConnection object by invoking the serviceConnected() and serviceDisconnected() call-back methods as necessary.

3.3.1 Instance Variables

3.3.1.1 mActiveConnections

Type: HashMap<ComponentName, ServiceDispatcher.ConnectionInfo>

Service specific information, in the form of a ConnectionInfo object, for each Service the associated ServiceConnection object is currently bound to.

The Service information is held in a map indexed by the name of the Service Component that implements the corresponding Service.

3.3.1.2 mConnection

Type: ServiceConnection

The ServiceConnection object this ServiceDispatcher is responsible for.

3.3.1.2 mActivityThread

Type: Handler

If non-null then the Handler this ServiceDispatcher should use to run call-back methods.

3.3.1.3 mFlags

Type: int

The set of bit flags specified in the call to the bindConnection() method which resulted in the creation of this ServiceDispatcher.

3.1.4 LoadedApk.ServiceDispatcher.ConnectionInfo

Package: android.app

Source: frameworks/base/core/java/android/app/LoadedApk.java

Definition: 908-911

There is a ConnectionInfo object for each distinct connection to a Service being managed by a ServiceDispatcher object.

3.1.4.1 Instance Variables

3.1.4.1.1 binder

Type: IBinder

The IBinder object used to interact with a given Service.

3.1.5 LoadedApk.ServiceDispatcher.InnerConnection

Package: android.app

Source: frameworks/base/core/java/android/app/LoadedApk.java

Definition: 913-926

The InnerConnection class is a sub-class of the Binder class which implements the IServiceConnection interface.

Each ServiceDispatcher object has an associated InnerConnection object.

The InnerConnection object is passed to the ActivityManagerService via a remote procedure call.

The ActivityManagerService uses the BinderProxy object which references the InnerConnection object to communicate changes to the Service connections which are being managed by the associated ServiceDispatcher object.

3.1.5.1 Instance Variables

3.1.5.1.1 mDispatcher

Type: WeakReference<LoadedApk.ServiceDispatcher>

A weak reference to the ServiceDispatcher that owns this InnerConnection object.

3.2 Class Relationship Diagram


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

Advertisements

12 Comments »

  1. […] ProcessRecord thread instance variable holds an ApplicationThreadProxy object which is created as a result of the call […]

    Pingback by Adventures In Distributed Garbage Collection: Part Five – The Cast Of Characters Concluded: Proxies « Just An Application — May 16, 2012 @ 8:25 am

  2. […] method calls retrieveServiceLocked() to obtain a ServiceRecord for the Service to be started, and bringUpServiceLocked() to create and start the Service if […]

    Pingback by Adventures In Distributed Garbage Collection: Part Six – Service Creation « Just An Application — May 17, 2012 @ 12:13 am

  3. […] connections associated with the Service and force is false then the method iterates over all the ConnectionRecords in the connections map of the […]

    Pingback by Adventures In Distributed Garbage Collection: Part Seven – Service Destruction « Just An Application — May 17, 2012 @ 9:00 am

  4. […] eventually results in a call to the ContextImpl implementation of the bindService() […]

    Pingback by Adventures In Distributed Garbage Collection: Part Eight – Binding To A Service « Just An Application — May 19, 2012 @ 6:28 am

  5. […] graph was generated using the LoadedApk object [0x40513e90] as the […]

    Pingback by Adventures In Distributed Garbage Collection: Part Nine – Post Bind Service Client State « Just An Application — May 20, 2012 @ 6:02 am

  6. […] ProcessRecord [0x4067a100] for the Service client process is present and has a reference to a single […]

    Pingback by Adventures In Distributed Garbage Collection: Part Eleven – Post Bind System Process State « Just An Application — May 22, 2012 @ 6:02 am

  7. […] LoadedApk object would no longer have a references to the ServiceDispatcher object via the mServices instance […]

    Pingback by Adventures In Distributed Garbage Collection: Part Thirteen – Post Unbind Service Client State « Just An Application — May 24, 2012 @ 6:09 am

  8. […] should no longer be a reference to the FastnetService object from the ActivityThread via its mServices instance […]

    Pingback by Adventures In Distributed Garbage Collection: Part Fourteen – Post Unbind Service State « Just An Application — May 25, 2012 @ 6:01 am

  9. […] ActivityManagerService would no longer hold a reference to the ServiceRecord representing the Fastnet Service via the mServices instance […]

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

  10. […] of a Binder reference cycle which will prevent it from being garbage collected, and we know that a ServiceRecord is a Java Binder object, so does this explain what is happening in this case […]

    Pingback by Adventures In Distributed Garbage Collection: Part Eighteen – The Great Service Record Mystery Revisited « Just An Application — June 6, 2012 @ 9:32 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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: