org.safs.android.engine
Class DroidEngine

java.lang.Object
  extended by InstrumentationTestRunner
      extended by org.safs.android.engine.DroidEngine
All Implemented Interfaces:
MessengerListener

public class DroidEngine
extends InstrumentationTestRunner
implements MessengerListener

Primary InstrumentationTestRunner used for remote controlled Android Automation in associated with a TCP Messenger Service.

This is the InstrumentationTestRunner that is considered the test package usually associated with a very specific target Package to be tested. However, in the case of SAFS we want to make a completely reusable test package that is NOT built with a specific target Package association. We want this general-purpose test framework to be usable to test all Android Applications via the data-driven SAFS framework.

The initial implementation, however, is not necessarily SAFS-specific.

How the remote control mechanism works:
The test package AdroidManifest.xml does need to have the Instrumentation tags set for the target Application to be tested. There is no getting around this:

 <instrumentation android:name="org.safs.android.engine.DroidEngine"
                  android:targetPackage="com.android.example.spinner"
                  android:label="General-Purpose SAFS Droid Automation Framework"/>
 
The AndroidManifest.xml then simply needs to be repackaged into a working test APK in order to test the target application.

The test consists of the following on-device assets:
1. TCP Messenger Service (SAFS Messenger Service),
2. DroidEngine test APK,
3. Target Application APK.

The remote control assets are simply:
1. Remote Controller implementing a TCP SocketServerListener,
2. TCP SocketServer binding to the on-device TCP Messenger Service for two-way communication.

There is a predefined TCP Protocol the remote TCP SocketServer and the on-device TCP Messenger Service must adhere to for proper signalling and synchronization.

When using the Droid Emulator, the remote controller must ensure the proper emulator port forwarding is set in order for the TCP Messenger Service to be able to communicate with the outside world.

See Also:
MessengerService

Field Summary
static java.lang.String resource_bind_service
           
static java.lang.String resource_service_attached
           
static java.lang.String resource_service_disconnect
           
static java.lang.String resource_service_release
           
static java.lang.String TAG
           
 
Constructor Summary
DroidEngine()
           
 
Method Summary
protected  void debug(java.lang.String message)
           
 void onCreate(Bundle savedInstanceState)
          Called when the Instrumentation class is first created.
 void onMessengerDebug(java.lang.String message)
          Receive debug logging requests from the Messenger Service
 void onRemoteConnected()
           
 void onRemoteDisconnected()
           
 void onRemoteDispatchFile(java.lang.String message)
           
 void onRemoteDispatchProps(java.util.Properties props)
           
 void onRemoteEngineShutdown()
          Remote request/command to tell the engine to perform a normal shutdown.
 void onRemoteMessage(java.lang.String message)
           
 void onRemoteShutdown()
          Notification that the Remote Controller has shutdown and is no longer available.
 void onServiceShutdown()
          Notification that the Messenger Service has shutdown and is no longer available.
 void onStart()
          Called automatically from start().
 void prepareNotification(int what)
          MessengerHandler preparing information for Thread switching.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TAG

public static final java.lang.String TAG
See Also:
Constant Field Values

resource_service_attached

public static final java.lang.String resource_service_attached
See Also:
Constant Field Values

resource_service_disconnect

public static final java.lang.String resource_service_disconnect
See Also:
Constant Field Values

resource_service_release

public static final java.lang.String resource_service_release
See Also:
Constant Field Values

resource_bind_service

public static final java.lang.String resource_bind_service
See Also:
Constant Field Values
Constructor Detail

DroidEngine

public DroidEngine()
Method Detail

debug

protected void debug(java.lang.String message)

onMessengerDebug

public void onMessengerDebug(java.lang.String message)
Receive debug logging requests from the Messenger Service

Specified by:
onMessengerDebug in interface MessengerListener

prepareNotification

public void prepareNotification(int what)
MessengerHandler preparing information for Thread switching.

Specified by:
prepareNotification in interface MessengerListener

onRemoteDispatchProps

public void onRemoteDispatchProps(java.util.Properties props)
Specified by:
onRemoteDispatchProps in interface MessengerListener

onRemoteDispatchFile

public void onRemoteDispatchFile(java.lang.String message)
Specified by:
onRemoteDispatchFile in interface MessengerListener

onRemoteMessage

public void onRemoteMessage(java.lang.String message)
Specified by:
onRemoteMessage in interface MessengerListener

onRemoteConnected

public void onRemoteConnected()
Specified by:
onRemoteConnected in interface MessengerListener

onRemoteDisconnected

public void onRemoteDisconnected()
Specified by:
onRemoteDisconnected in interface MessengerListener

onRemoteShutdown

public void onRemoteShutdown()
Notification that the Remote Controller has shutdown and is no longer available.

Specified by:
onRemoteShutdown in interface MessengerListener

onServiceShutdown

public void onServiceShutdown()
Notification that the Messenger Service has shutdown and is no longer available.

Specified by:
onServiceShutdown in interface MessengerListener

onRemoteEngineShutdown

public void onRemoteEngineShutdown()
Remote request/command to tell the engine to perform a normal shutdown.

Specified by:
onRemoteEngineShutdown in interface MessengerListener

onCreate

public void onCreate(Bundle savedInstanceState)
Called when the Instrumentation class is first created. Here we launch and bind to the TCP Messenger Service and then attempt to deduce the target Application we are going to be testing. Then we call start() to begin the instrumentation loop.

See Also:
doBindService(), getTargetPackageInfo(), #start()

onStart

public void onStart()
Called automatically from start(). Primary looping test thread remains active for as long as we are bound to a TCP Messenger Service. Synchronizes with the Message handler waiting for new valid instructions then routes test actions according to the content of the data received via the Messenger.

See Also:
#start(), messageLock