com.android.ddmlib
Class EmulatorConsole

java.lang.Object
  extended by com.android.ddmlib.EmulatorConsole

public final class EmulatorConsole
extends java.lang.Object

Provides control over emulated hardware of the Android emulator.

This is basically a wrapper around the command line console normally used with telnet.

Regarding line termination handling:
One of the issues is that the telnet protocol requires usage of \r\n. Most implementations don't enforce it (the dos one does). In this particular case, this is mostly irrelevant since we don't use telnet in Java, but that means we want to make sure we use the same line termination than what the console expects. The console code removes \r and waits for \n.

However this means you may receive \r\n when reading from the console.

This API will change in the near future.


Nested Class Summary
static class EmulatorConsole.GsmMode
          Gsm Mode enum.
static class EmulatorConsole.GsmStatus
          Gsm Status class
static class EmulatorConsole.NetworkStatus
          Network Status class
 
Field Summary
static int[] DOWNLOAD_SPEEDS
          Array of download speeds: full speed, gsm, hscsd, gprs, edge/egprs, umts/3g, hsdpa.
static int[] MIN_LATENCIES
          Array of delay values: no delay, gprs, edge/egprs, umts/3d
static java.lang.String[] NETWORK_LATENCIES
          Arrays of valid network latencies
static java.lang.String[] NETWORK_SPEEDS
          Arrays of valid network speeds
static java.lang.String RESULT_OK
           
 
Method Summary
 java.lang.String call(java.lang.String number)
          Initiate an incoming call on the emulator.
 java.lang.String cancelCall(java.lang.String number)
          Cancels a current call.
 void close()
          Closes this instance of the emulator console.
 java.lang.String getAvdName()
           
static EmulatorConsole getConsole(IDevice d)
          Returns an EmulatorConsole object for the given Device.
static java.lang.Integer getEmulatorPort(java.lang.String serialNumber)
          Return port of emulator given its serial number.
 EmulatorConsole.GsmStatus getGsmStatus()
          Returns the current gsm status of the emulator
 EmulatorConsole.NetworkStatus getNetworkStatus()
          Get the network status of the emulator.
 void kill()
          Sends a KILL command to the emulator.
 java.lang.String sendLocation(double longitude, double latitude, double elevation)
           
 java.lang.String sendSms(java.lang.String number, java.lang.String message)
          Sends an SMS to the emulator
 java.lang.String setGsmDataMode(EmulatorConsole.GsmMode mode)
          Sets the GSM data mode.
 java.lang.String setGsmVoiceMode(EmulatorConsole.GsmMode mode)
          Sets the GSM voice mode.
 java.lang.String setNetworkLatency(int selectionIndex)
          Sets the network latency.
 java.lang.String setNetworkSpeed(int selectionIndex)
          Sets the network speed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MIN_LATENCIES

public static final int[] MIN_LATENCIES
Array of delay values: no delay, gprs, edge/egprs, umts/3d


DOWNLOAD_SPEEDS

public static final int[] DOWNLOAD_SPEEDS
Array of download speeds: full speed, gsm, hscsd, gprs, edge/egprs, umts/3g, hsdpa.


NETWORK_SPEEDS

public static final java.lang.String[] NETWORK_SPEEDS
Arrays of valid network speeds


NETWORK_LATENCIES

public static final java.lang.String[] NETWORK_LATENCIES
Arrays of valid network latencies


RESULT_OK

public static final java.lang.String RESULT_OK
Method Detail

getConsole

@Nullable
public static EmulatorConsole getConsole(IDevice d)
Returns an EmulatorConsole object for the given Device. This can be an already existing console, or a new one if it hadn't been created yet. Note: emulator consoles don't automatically close when an emulator exists. It is the responsibility of higher level code to explicitly call close() when the emulator corresponding to a open console is killed.

Parameters:
d - The device that the console links to.
Returns:
an EmulatorConsole object or null if the connection failed.

getEmulatorPort

public static java.lang.Integer getEmulatorPort(java.lang.String serialNumber)
Return port of emulator given its serial number.

Parameters:
serialNumber - the emulator's serial number
Returns:
the integer port or null if it could not be determined

kill

public void kill()
Sends a KILL command to the emulator.


close

public void close()
Closes this instance of the emulator console.


getAvdName

public java.lang.String getAvdName()

getNetworkStatus

public EmulatorConsole.NetworkStatus getNetworkStatus()
Get the network status of the emulator.

Returns:
a EmulatorConsole.NetworkStatus object containing the EmulatorConsole.GsmStatus, or null if the query failed.

getGsmStatus

public EmulatorConsole.GsmStatus getGsmStatus()
Returns the current gsm status of the emulator

Returns:
a EmulatorConsole.GsmStatus object containing the gms status, or null if the query failed.

setGsmVoiceMode

public java.lang.String setGsmVoiceMode(EmulatorConsole.GsmMode mode)
                                 throws java.security.InvalidParameterException
Sets the GSM voice mode.

Parameters:
mode - the EmulatorConsole.GsmMode value.
Returns:
RESULT_OK if success, an error String otherwise.
Throws:
java.security.InvalidParameterException - if mode is an invalid value.

setGsmDataMode

public java.lang.String setGsmDataMode(EmulatorConsole.GsmMode mode)
                                throws java.security.InvalidParameterException
Sets the GSM data mode.

Parameters:
mode - the EmulatorConsole.GsmMode value
Returns:
RESULT_OK if success, an error String otherwise.
Throws:
java.security.InvalidParameterException - if mode is an invalid value.

call

public java.lang.String call(java.lang.String number)
Initiate an incoming call on the emulator.

Parameters:
number - a string representing the calling number.
Returns:
RESULT_OK if success, an error String otherwise.

cancelCall

public java.lang.String cancelCall(java.lang.String number)
Cancels a current call.

Parameters:
number - the number of the call to cancel
Returns:
RESULT_OK if success, an error String otherwise.

sendSms

public java.lang.String sendSms(java.lang.String number,
                                java.lang.String message)
Sends an SMS to the emulator

Parameters:
number - The sender phone number
message - The SMS message. \ characters must be escaped. The carriage return is the 2 character sequence {'\', 'n' }
Returns:
RESULT_OK if success, an error String otherwise.

setNetworkSpeed

public java.lang.String setNetworkSpeed(int selectionIndex)
Sets the network speed.

Parameters:
selectionIndex - The index in the NETWORK_SPEEDS table.
Returns:
RESULT_OK if success, an error String otherwise.

setNetworkLatency

public java.lang.String setNetworkLatency(int selectionIndex)
Sets the network latency.

Parameters:
selectionIndex - The index in the NETWORK_LATENCIES table.
Returns:
RESULT_OK if success, an error String otherwise.

sendLocation

public java.lang.String sendLocation(double longitude,
                                     double latitude,
                                     double elevation)