Add hardware support to AVD creation dialog.
Change-Id: Ia20b55c788191b40159b5c38b66f1da333179ccc
This commit is contained in:
@@ -24,43 +24,52 @@ import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class HardwareProperties {
|
||||
private final static Pattern PATTERN_PROP = Pattern.compile(
|
||||
"^([a-zA-Z0-9._-]+)\\s*=\\s*(.*)\\s*$");
|
||||
|
||||
|
||||
private final static String HW_PROP_NAME = "name";
|
||||
private final static String HW_PROP_TYPE = "type";
|
||||
private final static String HW_PROP_DEFAULT = "default";
|
||||
private final static String HW_PROP_ABSTRACT = "abstract";
|
||||
private final static String HW_PROP_DESC = "description";
|
||||
|
||||
|
||||
private final static String BOOLEAN_YES = "yes";
|
||||
private final static String BOOLEAN_NO = "no";
|
||||
public final static String[] BOOLEAN_VALUES = new String[] { BOOLEAN_YES, BOOLEAN_NO };
|
||||
public final static Pattern DISKSIZE_PATTERN = Pattern.compile("\\d+[MK]B");
|
||||
|
||||
public enum ValueType {
|
||||
INTEGER("integer"),
|
||||
BOOLEAN("boolean"),
|
||||
DISKSIZE("diskSize");
|
||||
|
||||
|
||||
private String mValue;
|
||||
|
||||
ValueType(String value) {
|
||||
mValue = value;
|
||||
}
|
||||
|
||||
|
||||
public String getValue() {
|
||||
return mValue;
|
||||
}
|
||||
|
||||
public static ValueType getEnum(String value) {
|
||||
for (ValueType type : values()) {
|
||||
if (type.mValue.equals(value)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static final class HardwareProperty {
|
||||
private String mName;
|
||||
private ValueType mType;
|
||||
@@ -68,40 +77,40 @@ public class HardwareProperties {
|
||||
private String mDefault;
|
||||
private String mAbstract;
|
||||
private String mDescription;
|
||||
|
||||
|
||||
public String getName() {
|
||||
return mName;
|
||||
}
|
||||
|
||||
|
||||
public ValueType getType() {
|
||||
return mType;
|
||||
}
|
||||
|
||||
|
||||
public String getDefault() {
|
||||
return mDefault;
|
||||
}
|
||||
|
||||
|
||||
public String getAbstract() {
|
||||
return mAbstract;
|
||||
}
|
||||
|
||||
|
||||
public String getDescription() {
|
||||
return mDescription;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parses the hardware definition file.
|
||||
* @param file the property file to parse
|
||||
* @param log the ISdkLog object receiving warning/error from the parsing.
|
||||
* @return the map of (key,value) pairs, or null if the parsing failed.
|
||||
*/
|
||||
public static List<HardwareProperty> parseHardwareDefinitions(File file, ISdkLog log) {
|
||||
public static Map<String, HardwareProperty> parseHardwareDefinitions(File file, ISdkLog log) {
|
||||
try {
|
||||
FileInputStream fis = new FileInputStream(file);
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(fis));
|
||||
|
||||
List<HardwareProperty> map = new ArrayList<HardwareProperty>();
|
||||
Map<String, HardwareProperty> map = new HashMap<String, HardwareProperty>();
|
||||
|
||||
String line = null;
|
||||
HardwareProperty prop = null;
|
||||
@@ -115,15 +124,15 @@ public class HardwareProperties {
|
||||
if (HW_PROP_NAME.equals(valueName)) {
|
||||
prop = new HardwareProperty();
|
||||
prop.mName = value;
|
||||
map.add(prop);
|
||||
map.put(prop.mName, prop);
|
||||
}
|
||||
|
||||
|
||||
if (prop == null) {
|
||||
log.warning("Error parsing '%1$s': missing '%2$s'",
|
||||
file.getAbsolutePath(), HW_PROP_NAME);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
if (HW_PROP_TYPE.equals(valueName)) {
|
||||
prop.mType = ValueType.getEnum(value);
|
||||
} else if (HW_PROP_DEFAULT.equals(valueName)) {
|
||||
@@ -140,7 +149,7 @@ public class HardwareProperties {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return map;
|
||||
} catch (FileNotFoundException e) {
|
||||
// this should not happen since we usually test the file existence before
|
||||
@@ -156,4 +165,16 @@ public class HardwareProperties {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of <var>value</var> in {@link #BOOLEAN_VALUES}.
|
||||
*/
|
||||
public static int getBooleanValueIndex(String value) {
|
||||
if (BOOLEAN_YES.equals(value)) {
|
||||
return 0;
|
||||
} else if (BOOLEAN_NO.equals(value)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user