Just An Application

May 15, 2012

Adventures In Distributed Garbage Collection: Part Three – The Cast Of Characters: Actors And Processes

In this example there are three different processes and seven distinct actors of five different types which interact using remote procedure calls and messages.

1.0 Actors

1.1 ActivityThread

Package: android.app

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

Process: Service Client

Process: Service

The ActivityThread class defines the main method which is used by the system to start an Android Application process

The method creates a singleton ActivityThread object which runs as the main thread of the prccess.

The ActivityThread object is responsible for managing the Android Application(s) and associated Android components running in the process via interaction with the ActivityManagerService.

1.1 ActivityThread.ApplicationThread

Package: android.app

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

Process: Service Client

Process: Service

Each ActivityThread object has an associated ApplicationThread object which implements the IApplicationThread interface.

The ApplicationThread is the actor within an Android Application process that the ActivityManagerService calls via remote procedure call when it needs to interact with an Android application running in that process.

In practice the ApplicationThread delegates all the requested actions to the ActivityThread.

1.2 ActivityManagerService

Package: com.android.server.am

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

Process: System

The ActivityManagerService is a singleton object which implements the IActivityManager interface. It runs in the SystemServer process.

It is responsible for managing the lifecycle of Android application processes and Android components such as Services, as well as the interactions between Android components in different processes.

It also implements the vast majority of Intent related functionality.

1.3 Service Component

Process: Service

The Service component is named in the Service declaration. It is the sub-class of the Service base class that implements the Service.

In this example it is declared as part of a standalone Application which runs in its own process.

    <?xml version="1.0" encoding="utf-8"?>
    <manifest 
        xmlns:android="http://schemas.android.com/apk/res/android"
        package="xper.service.fastnet"
        android:versionCode="1"
        android:versionName="1.0">
		
        <uses-sdk android:minSdkVersion="8" />

        <application 
            android:icon="@drawable/icon" 
            android:label="@string/app_name">
            <service 
                android:name="FastnetService">
                <intent-filter>
                    <action 
                        android:name="xper.service.fastnet.ACTION_FASTNET">
                    </action>
                </intent-filter>
            </service>
        </application>

    </manifest>

This declares the Service component to be the class

    xper.service.fastnet.FastnetService

1.4 Service Client

The Service client is the Android component which has established a connection to the Service.

In this example the Service client is an Activity although in general this does not have to be the case.

The Activity is declared as follows

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="xper.service.fastnet.client"
        android:versionCode="1"
        android:versionName="1.0">
        <uses-sdk android:minSdkVersion="8" />

        <application 
            android:icon="@drawable/icon" 
            android:label="@string/app_name">
            <activity 
                android:name=".FastnetClientActivity"
                android:label="@string/app_name">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>

        </application>
    </manifest>

1.0 Processes

1.1 Service Client

This is the process in which the Android component which is the client of the Service runs.

In this example it is distinct from both the Service process and the System process although in general this does not have to be the case.

1.2 Service

This is the process in which the Service component which implements the Service runs.

In this example it is distinct from both the Service client process and the SystemServer process although in general this does not have to be the case.

1.3 System

This is the process in the which the ActivityManagerService runs. The process is started by Android itself as part of the boot sequence.


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

Advertisements

16 Comments »

  1. […] ActivityManagerService holds a ProcessRecord object for each such […]

    Pingback by Adventures In Distributed Garbage Collection: Part Four – The Cast Of Characters Continued: Objects And Actor State « Just An Application — May 15, 2012 @ 8:28 pm

  2. […] argument "activity". In an Android Application process this returns a BinderProxy object for the ActivityManagerService object in the System […]

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

  3. […] component that implements a Service is created in the appropriate process if it does not already exist when […]

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

  4. […] component which implements a Service is destroyed […]

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

  5. […] Actor: ActivityManagerService […]

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

  6. […] following code in the Service Client calls the Activity’s implementation of the […]

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

  7. […] source code to derive a diagram which shows the Service related objects which should exist in the Service client process and their relationships following a successful call to […]

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

  8. […] source code to derive a diagram which shows the Service related objects which should exist in the Service process and their relationships once the Service client has bound to the […]

    Pingback by Adventures In Distributed Garbage Collection: Part Ten – Post Bind Service State « Just An Application — May 21, 2012 @ 6:00 am

  9. […] 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 […]

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

  10. […] following code in the Service Client calls the Activity’s implementation of the […]

    Pingback by Adventures In Distributed Garbage Collection: Part Twelve – Unbinding From A Service « Just An Application — May 23, 2012 @ 6:00 am

  11. […] Once the client has unbound from the Fastnet Service then on the basis of the source code we would expect that in the Service client process […]

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

  12. […] 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

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

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

  14. […] the ServiceRecord object representing a non-existent Service still exist in the Java heap of the System process […]

    Pingback by Adventures In Distributed Garbage Collection: Part Sixteen – The Great ServiceRecord Mystery « Just An Application — May 30, 2012 @ 9:10 am

  15. […] In this case 368 is the id of the process running the Malin Service, 357 is the id of the process running the client, and 60 is the id of the System process. […]

    Pingback by Adventures In Distributed Garbage Collection: Part Seventeen – Binders And Garbage Collection « Just An Application — June 1, 2012 @ 9:34 am

  16. […] that the ServiceRecord object representing a Service is passed to the process running that Service via a remote procedure call to the scheduleCreateService() method of the ApplicationThread […]

    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: