com.android.sdklib.internal.avd
Class AvdManager

java.lang.Object
  extended by com.android.sdklib.internal.avd.AvdManager

public class AvdManager
extends java.lang.Object

Android Virtual Device Manager to manage AVDs.


Nested Class Summary
static class AvdManager.AvdConflict
          Status returned by isAvdNameConflicting(String).
 
Field Summary
static java.lang.String AVD_FOLDER_EXTENSION
           
static java.lang.String AVD_INFO_ABS_PATH
          The *absolute* path to the AVD folder (which contains the #CONFIG_INI file).
static java.lang.String AVD_INFO_REL_PATH
          The path to the AVD folder (which contains the #CONFIG_INI file) relative to the AndroidLocation.FOLDER_DOT_ANDROID.
static java.lang.String AVD_INFO_TARGET
          The IAndroidTarget.hashString() of the AVD.
static java.lang.String AVD_INI_ABI_TYPE
          AVD/config.ini key name representing the abi type of the specific avd
static java.lang.String AVD_INI_CAMERA_BACK
          AVD/config.ini key name representing how to emulate the rear facing camera
static java.lang.String AVD_INI_CAMERA_FRONT
          AVD/config.ini key name representing how to emulate the front facing camera
static java.lang.String AVD_INI_CPU_ARCH
          AVD/config.ini key name representing the CPU architecture of the specific avd
static java.lang.String AVD_INI_CPU_MODEL
          AVD/config.ini key name representing the CPU architecture of the specific avd
static java.lang.String AVD_INI_DATA_PARTITION_SIZE
          AVD/config.ini key name representing the size of the data partition
static java.lang.String AVD_INI_DEVICE_HASH
          AVD/config.ini key name representing the hash of the device this AVD is based on
static java.lang.String AVD_INI_DEVICE_MANUFACTURER
          AVD/config.ini key name representing the manufacturer of the device this avd was based on.
static java.lang.String AVD_INI_DEVICE_NAME
          AVD/config.ini key name representing the name of the device this avd was based on.
static java.lang.String AVD_INI_ENCODING
          Charset encoding used by the avd.ini/config.ini.
static java.lang.String AVD_INI_GPU_EMULATION
          AVD/config.ini key name representing whether hardware OpenGLES emulation is enabled
static java.lang.String AVD_INI_IMAGES_1
          AVD/config.ini key name representing the first path where the emulator looks for system images.
static java.lang.String AVD_INI_IMAGES_2
          AVD/config.ini key name representing the second path where the emulator looks for system images.
static java.lang.String AVD_INI_RAM_SIZE
          AVD/config.ini key name representing the amount of RAM the emulated device should have
static java.lang.String AVD_INI_SDCARD_PATH
          AVD/config.ini key name representing the path to the sdcard file.
static java.lang.String AVD_INI_SDCARD_SIZE
          AVD/config.ini key name representing the size of the SD card.
static java.lang.String AVD_INI_SKIN_DYNAMIC
          AVD/config.ini key name representing whether a dynamic skin should be displayed.
static java.lang.String AVD_INI_SKIN_NAME
          AVD/config.ini key name representing an UI name for the skin.
static java.lang.String AVD_INI_SKIN_PATH
          AVD/config.ini key name representing the SDK-relative path of the skin folder, if any, or a 320x480 like constant for a numeric skin size.
static java.lang.String AVD_INI_SNAPSHOT_PRESENT
          AVD/config.ini key name representing the presence of the snapshots file.
static java.lang.String AVD_INI_VM_HEAP_SIZE
          AVD/config.ini key name representing the amount of memory available to applications by default
static java.lang.String CHARS_AVD_NAME
          List of valid characters for an AVD name.
static java.lang.String HARDWARE_INI
           
static java.util.regex.Pattern NUMERIC_SKIN_SIZE
          Pattern to match pixel-sized skin "names", e.g.
static java.util.regex.Pattern RE_AVD_NAME
          Regex used to validate characters that compose an AVD name.
static long SDCARD_MAX_BYTE_SIZE
          Maximal size of an SDCard image file in bytes.
static long SDCARD_MIN_BYTE_SIZE
          Minimal size of an SDCard image file in bytes.
static int SDCARD_NOT_SIZE_PATTERN
          The sdcard string doesn't look like a size, it might be a path instead.
static int SDCARD_SIZE_INVALID
          The sdcard string looks like a size number+suffix but the number failed to decode.
static int SDCARD_SIZE_NOT_IN_RANGE
          The sdcard string represents a valid number but the size is outside of the allowed range.
 
Constructor Summary
protected AvdManager(SdkManager sdkManager, com.android.utils.ILogger log)
          Creates an AVD Manager for a given SDK represented by a SdkManager.
 
Method Summary
 AvdInfo createAvd(java.io.File avdFolder, java.lang.String avdName, IAndroidTarget target, java.lang.String abiType, java.lang.String skinName, java.lang.String sdcard, java.util.Map<java.lang.String,java.lang.String> hardwareConfig, boolean createSnapshot, boolean removePrevious, boolean editExisting, com.android.utils.ILogger log)
          Creates a new AVD.
 boolean deleteAvd(AvdInfo avdInfo, com.android.utils.ILogger log)
          Actually deletes the files of an existing AVD.
 AvdInfo[] getAllAvds()
          Returns all the existing AVDs.
 AvdInfo getAvd(java.lang.String name, boolean validAvdOnly)
          Returns the AvdInfo matching the given name.
 java.lang.String getBaseAvdFolder()
          Returns the base folder where AVDs are created.
 AvdInfo[] getBrokenAvds()
          Returns all the broken AVDs.
static AvdManager getInstance(SdkManager sdkManager, com.android.utils.ILogger log)
           
 SdkManager getSdkManager()
          Returns the SdkManager associated with the AvdManager.
 java.io.File getSkinPath(java.lang.String skinName, IAndroidTarget target)
          Returns the full absolute OS path to a skin specified by name for a given target.
 java.lang.String getSkinRelativePath(java.lang.String skinName, IAndroidTarget target, com.android.utils.ILogger log)
          Returns the path to the skin, as a relative path to the SDK.
 AvdInfo[] getValidAvds()
          Returns all the valid AVDs.
 com.android.utils.Pair<AvdManager.AvdConflict,java.lang.String> isAvdNameConflicting(java.lang.String name)
          Returns whether this AVD name would generate a conflict.
 boolean moveAvd(AvdInfo avdInfo, java.lang.String newName, java.lang.String paramFolderPath, com.android.utils.ILogger log)
          Moves and/or rename an existing AVD and its files.
static long parseSdcardSize(java.lang.String sdcard, java.lang.String[] parsedStrings)
          Parse the sdcard string to decode the size.
 void reloadAvds(com.android.utils.ILogger log)
          Reloads the AVD list.
 boolean removeAvd(AvdInfo avdInfo)
          Removes an AvdInfo from the internal list.
 void updateAvd(AvdInfo avd, com.android.utils.ILogger log)
          Updates an AVD with new path to the system image folders.
 void updateAvd(AvdInfo avd, java.util.Map<java.lang.String,java.lang.String> newProperties, AvdInfo.AvdStatus status, com.android.utils.ILogger log)
           
 void updateAvd(java.lang.String name, com.android.utils.ILogger log)
          Updates an AVD with new path to the system image folders.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AVD_FOLDER_EXTENSION

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

AVD_INI_ENCODING

public static final java.lang.String AVD_INI_ENCODING
Charset encoding used by the avd.ini/config.ini.

See Also:
Constant Field Values

AVD_INFO_ABS_PATH

public static final java.lang.String AVD_INFO_ABS_PATH
The *absolute* path to the AVD folder (which contains the #CONFIG_INI file).

See Also:
Constant Field Values

AVD_INFO_REL_PATH

public static final java.lang.String AVD_INFO_REL_PATH
The path to the AVD folder (which contains the #CONFIG_INI file) relative to the AndroidLocation.FOLDER_DOT_ANDROID. This information is written in the avd ini only if the AVD folder is located under the .android path (that is the relative that has no backward .. references).

See Also:
Constant Field Values

AVD_INFO_TARGET

public static final java.lang.String AVD_INFO_TARGET
The IAndroidTarget.hashString() of the AVD.

See Also:
Constant Field Values

AVD_INI_ABI_TYPE

public static final java.lang.String AVD_INI_ABI_TYPE
AVD/config.ini key name representing the abi type of the specific avd

See Also:
Constant Field Values

AVD_INI_CPU_ARCH

public static final java.lang.String AVD_INI_CPU_ARCH
AVD/config.ini key name representing the CPU architecture of the specific avd

See Also:
Constant Field Values

AVD_INI_CPU_MODEL

public static final java.lang.String AVD_INI_CPU_MODEL
AVD/config.ini key name representing the CPU architecture of the specific avd

See Also:
Constant Field Values

AVD_INI_DEVICE_MANUFACTURER

public static final java.lang.String AVD_INI_DEVICE_MANUFACTURER
AVD/config.ini key name representing the manufacturer of the device this avd was based on.

See Also:
Constant Field Values

AVD_INI_DEVICE_NAME

public static final java.lang.String AVD_INI_DEVICE_NAME
AVD/config.ini key name representing the name of the device this avd was based on.

See Also:
Constant Field Values

AVD_INI_SKIN_PATH

public static final java.lang.String AVD_INI_SKIN_PATH
AVD/config.ini key name representing the SDK-relative path of the skin folder, if any, or a 320x480 like constant for a numeric skin size.

See Also:
NUMERIC_SKIN_SIZE, Constant Field Values

AVD_INI_SKIN_NAME

public static final java.lang.String AVD_INI_SKIN_NAME
AVD/config.ini key name representing an UI name for the skin. This config key is ignored by the emulator. It is only used by the SDK manager or tools to give a friendlier name to the skin. If missing, use the AVD_INI_SKIN_PATH key instead.

See Also:
Constant Field Values

AVD_INI_SKIN_DYNAMIC

public static final java.lang.String AVD_INI_SKIN_DYNAMIC
AVD/config.ini key name representing whether a dynamic skin should be displayed.

See Also:
Constant Field Values

AVD_INI_SDCARD_PATH

public static final java.lang.String AVD_INI_SDCARD_PATH
AVD/config.ini key name representing the path to the sdcard file. If missing, the default name "sdcard.img" will be used for the sdcard, if there's such a file.

See Also:
SDCARD_IMG, Constant Field Values

AVD_INI_SDCARD_SIZE

public static final java.lang.String AVD_INI_SDCARD_SIZE
AVD/config.ini key name representing the size of the SD card. This property is for UI purposes only. It is not used by the emulator.

See Also:
SDCARD_SIZE_PATTERN, parseSdcardSize(String, String[]), Constant Field Values

AVD_INI_IMAGES_1

public static final java.lang.String AVD_INI_IMAGES_1
AVD/config.ini key name representing the first path where the emulator looks for system images. Typically this is the path to the add-on system image or the path to the platform system image if there's no add-on.

The emulator looks at AVD_INI_IMAGES_1 before AVD_INI_IMAGES_2.

See Also:
Constant Field Values

AVD_INI_IMAGES_2

public static final java.lang.String AVD_INI_IMAGES_2
AVD/config.ini key name representing the second path where the emulator looks for system images. Typically this is the path to the platform system image.

See Also:
AVD_INI_IMAGES_1, Constant Field Values

AVD_INI_SNAPSHOT_PRESENT

public static final java.lang.String AVD_INI_SNAPSHOT_PRESENT
AVD/config.ini key name representing the presence of the snapshots file. This property is for UI purposes only. It is not used by the emulator.

See Also:
SNAPSHOTS_IMG, Constant Field Values

AVD_INI_GPU_EMULATION

public static final java.lang.String AVD_INI_GPU_EMULATION
AVD/config.ini key name representing whether hardware OpenGLES emulation is enabled

See Also:
Constant Field Values

AVD_INI_CAMERA_FRONT

public static final java.lang.String AVD_INI_CAMERA_FRONT
AVD/config.ini key name representing how to emulate the front facing camera

See Also:
Constant Field Values

AVD_INI_CAMERA_BACK

public static final java.lang.String AVD_INI_CAMERA_BACK
AVD/config.ini key name representing how to emulate the rear facing camera

See Also:
Constant Field Values

AVD_INI_RAM_SIZE

public static final java.lang.String AVD_INI_RAM_SIZE
AVD/config.ini key name representing the amount of RAM the emulated device should have

See Also:
Constant Field Values

AVD_INI_VM_HEAP_SIZE

public static final java.lang.String AVD_INI_VM_HEAP_SIZE
AVD/config.ini key name representing the amount of memory available to applications by default

See Also:
Constant Field Values

AVD_INI_DATA_PARTITION_SIZE

public static final java.lang.String AVD_INI_DATA_PARTITION_SIZE
AVD/config.ini key name representing the size of the data partition

See Also:
Constant Field Values

AVD_INI_DEVICE_HASH

public static final java.lang.String AVD_INI_DEVICE_HASH
AVD/config.ini key name representing the hash of the device this AVD is based on

See Also:
Constant Field Values

NUMERIC_SKIN_SIZE

public static final java.util.regex.Pattern NUMERIC_SKIN_SIZE
Pattern to match pixel-sized skin "names", e.g. "320x480".


SDCARD_MIN_BYTE_SIZE

public static final long SDCARD_MIN_BYTE_SIZE
Minimal size of an SDCard image file in bytes. Currently 9 MiB.

See Also:
Constant Field Values

SDCARD_MAX_BYTE_SIZE

public static final long SDCARD_MAX_BYTE_SIZE
Maximal size of an SDCard image file in bytes. Currently 1023 GiB.

See Also:
Constant Field Values

SDCARD_SIZE_NOT_IN_RANGE

public static final int SDCARD_SIZE_NOT_IN_RANGE
The sdcard string represents a valid number but the size is outside of the allowed range.

See Also:
Constant Field Values

SDCARD_SIZE_INVALID

public static final int SDCARD_SIZE_INVALID
The sdcard string looks like a size number+suffix but the number failed to decode.

See Also:
Constant Field Values

SDCARD_NOT_SIZE_PATTERN

public static final int SDCARD_NOT_SIZE_PATTERN
The sdcard string doesn't look like a size, it might be a path instead.

See Also:
Constant Field Values

RE_AVD_NAME

public static final java.util.regex.Pattern RE_AVD_NAME
Regex used to validate characters that compose an AVD name.


CHARS_AVD_NAME

public static final java.lang.String CHARS_AVD_NAME
List of valid characters for an AVD name. Used for display purposes.

See Also:
Constant Field Values

HARDWARE_INI

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

AvdManager

protected AvdManager(SdkManager sdkManager,
                     com.android.utils.ILogger log)
              throws com.android.prefs.AndroidLocation.AndroidLocationException
Creates an AVD Manager for a given SDK represented by a SdkManager.

Parameters:
sdkManager - The SDK.
log - The log object to receive the log of the initial loading of the AVDs. This log object is not kept by this instance of AvdManager and each method takes its own logger. The rationale is that the AvdManager might be called from a variety of context, each with different logging needs. Cannot be null.
Throws:
com.android.prefs.AndroidLocation.AndroidLocationException
Method Detail

getInstance

public static AvdManager getInstance(SdkManager sdkManager,
                                     com.android.utils.ILogger log)
                              throws com.android.prefs.AndroidLocation.AndroidLocationException
Throws:
com.android.prefs.AndroidLocation.AndroidLocationException

getBaseAvdFolder

public java.lang.String getBaseAvdFolder()
                                  throws com.android.prefs.AndroidLocation.AndroidLocationException
Returns the base folder where AVDs are created.

Throws:
com.android.prefs.AndroidLocation.AndroidLocationException

getSdkManager

public SdkManager getSdkManager()
Returns the SdkManager associated with the AvdManager.


parseSdcardSize

public static long parseSdcardSize(java.lang.String sdcard,
                                   java.lang.String[] parsedStrings)
Parse the sdcard string to decode the size. Returns:

Parameters:
sdcard - The sdcard string, which can be a file path, a size string or something else.
parsedStrings - If non-null, an array of 2 strings. The first string will be filled with the parsed numeric size and the second one will be filled with the parsed suffix. This is filled even if the returned size is deemed out of range or failed to parse. The values are null if the sdcard is not a size pattern.
Returns:
A size in byte if > 0, or SDCARD_SIZE_NOT_IN_RANGE, SDCARD_SIZE_INVALID or SDCARD_NOT_SIZE_PATTERN as error codes.

getAllAvds

public AvdInfo[] getAllAvds()
Returns all the existing AVDs.

Returns:
a newly allocated array containing all the AVDs.

getValidAvds

public AvdInfo[] getValidAvds()
Returns all the valid AVDs.

Returns:
a newly allocated array containing all valid the AVDs.

getBrokenAvds

public AvdInfo[] getBrokenAvds()
Returns all the broken AVDs.

Returns:
a newly allocated array containing all the broken AVDs.

getAvd

public AvdInfo getAvd(java.lang.String name,
                      boolean validAvdOnly)
Returns the AvdInfo matching the given name.

The search is case-insensitive.

Parameters:
name - the name of the AVD to return
validAvdOnly - if true, only look through the list of valid AVDs.
Returns:
the matching AvdInfo or null if none were found.

isAvdNameConflicting

public com.android.utils.Pair<AvdManager.AvdConflict,java.lang.String> isAvdNameConflicting(java.lang.String name)
Returns whether this AVD name would generate a conflict.

Parameters:
name - the name of the AVD to return
Returns:
A pair of AvdManager.AvdConflict and the path or AVD name that conflicts.

reloadAvds

public void reloadAvds(com.android.utils.ILogger log)
                throws com.android.prefs.AndroidLocation.AndroidLocationException
Reloads the AVD list.

Parameters:
log - the log object to receive action logs. Cannot be null.
Throws:
com.android.prefs.AndroidLocation.AndroidLocationException - if there was an error finding the location of the AVD folder.

createAvd

public AvdInfo createAvd(java.io.File avdFolder,
                         java.lang.String avdName,
                         IAndroidTarget target,
                         java.lang.String abiType,
                         java.lang.String skinName,
                         java.lang.String sdcard,
                         java.util.Map<java.lang.String,java.lang.String> hardwareConfig,
                         boolean createSnapshot,
                         boolean removePrevious,
                         boolean editExisting,
                         com.android.utils.ILogger log)
Creates a new AVD. It is expected that there is no existing AVD with this name already.

Parameters:
avdFolder - the data folder for the AVD. It will be created as needed. Unless you want to locate it in a specific directory, the ideal default is AvdManager.AvdInfo.getAvdFolder.
avdName - the name of the AVD
target - the target of the AVD
abiType - the abi type of the AVD
skinName - the name of the skin. Can be null. Must have been verified by caller.
sdcard - the parameter value for the sdCard. Can be null. This is either a path to an existing sdcard image or a sdcard size (\d+, \d+K, \dM).
hardwareConfig - the hardware setup for the AVD. Can be null to use defaults.
createSnapshot - If true copy a blank snapshot image into the AVD.
removePrevious - If true remove any previous files.
editExisting - If true, edit an existing AVD, changing only the minimum required. This won't remove files unless required or unless removePrevious is set.
log - the log object to receive action logs. Cannot be null.
Returns:
The new AvdInfo in case of success (which has just been added to the internal list) or null in case of failure.

getSkinRelativePath

public java.lang.String getSkinRelativePath(java.lang.String skinName,
                                            IAndroidTarget target,
                                            com.android.utils.ILogger log)
Returns the path to the skin, as a relative path to the SDK.

Parameters:
skinName - The name of the skin to find. Case-sensitive.
target - The target where to find the skin.
log - the log object to receive action logs. Cannot be null.

getSkinPath

public java.io.File getSkinPath(java.lang.String skinName,
                                IAndroidTarget target)
Returns the full absolute OS path to a skin specified by name for a given target.

Parameters:
skinName - The name of the skin to find. Case-sensitive.
target - The target where to find the skin.
Returns:
a File that may or may not actually exist.

deleteAvd

public boolean deleteAvd(AvdInfo avdInfo,
                         com.android.utils.ILogger log)
Actually deletes the files of an existing AVD.

This also remove it from the manager's list, The caller does not need to call removeAvd(AvdInfo) afterwards.

This method is designed to somehow work with an unavailable AVD, that is an AVD that could not be loaded due to some error. That means this method still tries to remove the AVD ini file or its folder if it can be found. An error will be output if any of these operations fail.

Parameters:
avdInfo - the information on the AVD to delete
log - the log object to receive action logs. Cannot be null.
Returns:
True if the AVD was deleted with no error.

moveAvd

public boolean moveAvd(AvdInfo avdInfo,
                       java.lang.String newName,
                       java.lang.String paramFolderPath,
                       com.android.utils.ILogger log)
Moves and/or rename an existing AVD and its files. This also change it in the manager's list.

The caller should make sure the name or path given are valid, do not exist and are actually different than current values.

Parameters:
avdInfo - the information on the AVD to move.
newName - the new name of the AVD if non null.
paramFolderPath - the new data folder if non null.
log - the log object to receive action logs. Cannot be null.
Returns:
True if the move succeeded or there was nothing to do. If false, this method will have had already output error in the log.

removeAvd

public boolean removeAvd(AvdInfo avdInfo)
Removes an AvdInfo from the internal list.

Parameters:
avdInfo - The AvdInfo to remove.
Returns:
true if this AvdInfo was present and has been removed.

updateAvd

public void updateAvd(java.lang.String name,
                      com.android.utils.ILogger log)
               throws java.io.IOException
Updates an AVD with new path to the system image folders.

Parameters:
name - the name of the AVD to update.
log - the log object to receive action logs. Cannot be null.
Throws:
java.io.IOException

updateAvd

public void updateAvd(AvdInfo avd,
                      com.android.utils.ILogger log)
               throws java.io.IOException
Updates an AVD with new path to the system image folders.

Parameters:
avd - the AVD to update.
log - the log object to receive action logs. Cannot be null.
Throws:
java.io.IOException

updateAvd

public void updateAvd(AvdInfo avd,
                      java.util.Map<java.lang.String,java.lang.String> newProperties,
                      AvdInfo.AvdStatus status,
                      com.android.utils.ILogger log)
               throws java.io.IOException
Throws:
java.io.IOException