com.android.ddmlib
Class EmulatorConsole

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

public final class EmulatorConsole
extends 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
 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 String[] NETWORK_LATENCIES
          Arrays of valid network latencies
static String[] NETWORK_SPEEDS
          Arrays of valid network speeds
static String RESULT_OK
           
 
Method Summary
 String call(String number)
          Initiate an incoming call on the emulator.
 String cancelCall(String number)
          Cancels a current call.
 String getAvdName()
           
static EmulatorConsole getConsole(IDevice d)
          Returns an EmulatorConsole object for the given Device.
static Integer getEmulatorPort(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.
 String sendLocation(double longitude, double latitude, double elevation)
           
 String sendSms(String number, String message)
          Sends an SMS to the emulator
 String setGsmDataMode(EmulatorConsole.GsmMode mode)
          Sets the GSM data mode.
 String setGsmVoiceMode(EmulatorConsole.GsmMode mode)
          Sets the GSM voice mode.
 String setNetworkLatency(int selectionIndex)
          Sets the network latency.
 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 final int[] DOWNLOAD_SPEEDS
Array of download speeds: full speed, gsm, hscsd, gprs, edge/egprs, umts/3g, hsdpa.


NETWORK_SPEEDS

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


NETWORK_LATENCIES

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


RESULT_OK

public static final String RESULT_OK
Method Detail

getConsole

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.

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

getEmulatorPort

public static Integer getEmulatorPort(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.


getAvdName

public 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 String setGsmVoiceMode(EmulatorConsole.GsmMode mode)
                       throws InvalidParameterException
Sets the GSM voice mode.

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

setGsmDataMode

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

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

call

public String call(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 String cancelCall(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 String sendSms(String number,
                      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 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 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 String sendLocation(double longitude,
                           double latitude,
                           double elevation)


Copyright © 2008-2012. All Rights Reserved.