diff options
Diffstat (limited to 'sdkmanager')
9 files changed, 246 insertions, 183 deletions
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/devices/DeviceManager.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/devices/DeviceManager.java index 37b6876..c17a4df 100644 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/devices/DeviceManager.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/devices/DeviceManager.java @@ -17,6 +17,7 @@ package com.android.sdklib.devices; import com.android.SdkConstants; +import com.android.annotations.NonNull; import com.android.annotations.Nullable; import com.android.prefs.AndroidLocation; import com.android.prefs.AndroidLocation.AndroidLocationException; @@ -56,20 +57,26 @@ import javax.xml.transform.TransformerFactoryConfigurationError; */ public class DeviceManager { - private final static String sDeviceProfilesProp = "DeviceProfiles"; - private final static Pattern sPathPropertyPattern = Pattern.compile("^" + PkgProps.EXTRA_PATH - + "=" + sDeviceProfilesProp + "$"); + private static final String DEVICE_PROFILES_PROP = "DeviceProfiles"; + private static final Pattern PATH_PROPERTY_PATTERN = + Pattern.compile("^" + PkgProps.EXTRA_PATH + "=" + DEVICE_PROFILES_PROP + "$"); private ILogger mLog; - // Vendor devices can't be a static list since they change based on the SDK - // Location private List<Device> mVendorDevices; - // Keeps track of where the currently loaded vendor devices were loaded from - private String mVendorDevicesLocation = ""; - private static List<Device> mUserDevices; - private static List<Device> mDefaultDevices; - private static final Object sLock = new Object(); - private static final List<DevicesChangeListener> sListeners = - new ArrayList<DevicesChangeListener>(); + private List<Device> mUserDevices; + private List<Device> mDefaultDevices; + private final Object mLock = new Object(); + private final List<DevicesChangedListener> sListeners = + new ArrayList<DevicesChangedListener>(); + private final String mOsSdkPath; + + /** getDevices() flag to list user devices. */ + public static final int USER_DEVICES = 1; + /** getDevices() flag to list default devices. */ + public static final int DEFAULT_DEVICES = 2; + /** getDevices() flag to list vendor devices. */ + public static final int VENDOR_DEVICES = 4; + /** getDevices() flag to list all devices. */ + public static final int ALL_DEVICES = USER_DEVICES | DEFAULT_DEVICES | VENDOR_DEVICES; public static enum DeviceStatus { /** @@ -86,10 +93,26 @@ public class DeviceManager { MISSING; } - // TODO: Refactor this to look more like AvdManager so that we don't have - // multiple instances in the same application, which forces us to parse - // the XML multiple times when we don't have to. - public DeviceManager(ILogger log) { + /** + * Creates a new instance of DeviceManager. + * + * @param osSdkPath Path to the current SDK. If null or invalid, vendor devices are ignored. + * @param log SDK logger instance. Should be non-null. + */ + public static DeviceManager createInstance(@Nullable String osSdkPath, @NonNull ILogger log) { + // TODO consider using a cache and reusing the same instance of the device manager + // for the same manager/log combo. + return new DeviceManager(osSdkPath, log); + } + + /** + * Creates a new instance of DeviceManager. + * + * @param osSdkPath Path to the current SDK. If null or invalid, vendor devices are ignored. + * @param log SDK logger instance. Should be non-null. + */ + private DeviceManager(@Nullable String osSdkPath, @NonNull ILogger log) { + mOsSdkPath = osSdkPath; mLog = log; } @@ -97,11 +120,11 @@ public class DeviceManager { * Interface implemented by objects which want to know when changes occur to the {@link Device} * lists. */ - public static interface DevicesChangeListener { + public static interface DevicesChangedListener { /** * Called after one of the {@link Device} lists has been updated. */ - public void onDevicesChange(); + public void onDevicesChanged(); } /** @@ -109,7 +132,7 @@ public class DeviceManager { * * @param listener The listener to add. Ignored if already registered. */ - public void registerListener(DevicesChangeListener listener) { + public void registerListener(DevicesChangedListener listener) { if (listener != null) { synchronized (sListeners) { if (!sListeners.contains(listener)) { @@ -125,15 +148,14 @@ public class DeviceManager { * * @param listener The listener to remove. */ - public boolean unregisterListener(DevicesChangeListener listener) { + public boolean unregisterListener(DevicesChangedListener listener) { synchronized (sListeners) { return sListeners.remove(listener); } } - public DeviceStatus getDeviceStatus( - @Nullable String sdkLocation, String name, String manufacturer, int hashCode) { - Device d = getDevice(sdkLocation, name, manufacturer); + public DeviceStatus getDeviceStatus(String name, String manufacturer, int hashCode) { + Device d = getDevice(name, manufacturer); if (d == null) { return DeviceStatus.MISSING; } else { @@ -141,46 +163,64 @@ public class DeviceManager { } } - public Device getDevice(@Nullable String sdkLocation, String name, String manufacturer) { - List<Device> devices; - if (sdkLocation != null) { - devices = getDevices(sdkLocation); - } else { - devices = new ArrayList<Device>(getDefaultDevices()); - devices.addAll(getUserDevices()); - } - for (Device d : devices) { - if (d.getName().equals(name) && d.getManufacturer().equals(manufacturer)) { - return d; + public Device getDevice(String name, String manufacturer) { + initDevicesLists(); + for (List<?> devices : + new List<?>[] { mUserDevices, mDefaultDevices, mVendorDevices } ) { + if (devices != null) { + @SuppressWarnings("unchecked") List<Device> devicesList = (List<Device>) devices; + for (Device d : devicesList) { + if (d.getName().equals(name) && d.getManufacturer().equals(manufacturer)) { + return d; + } + } } } return null; } /** - * Returns both vendor provided and user created {@link Device}s. + * Returns the known {@link Device} list. * - * @param sdkLocation Location of the Android SDK - * @return A list of both vendor and user provided {@link Device}s + * @param deviceFilter A combination of USER_DEVICES, VENDOR_DEVICES and DEFAULT_DEVICES + * or the constant ALL_DEVICES. + * @return A copy of the list of {@link Device}s. Can be empty but not null. */ - public List<Device> getDevices(String sdkLocation) { - List<Device> devices = new ArrayList<Device>(getVendorDevices(sdkLocation)); - devices.addAll(getDefaultDevices()); - devices.addAll(getUserDevices()); + public List<Device> getDevices(int deviceFilter) { + initDevicesLists(); + List<Device> devices = new ArrayList<Device>(); + if (mUserDevices != null && (deviceFilter & USER_DEVICES) != 0) { + devices.addAll(mUserDevices); + } + if (mDefaultDevices != null && (deviceFilter & DEFAULT_DEVICES) != 0) { + devices.addAll(mDefaultDevices); + } + if (mVendorDevices != null && (deviceFilter & VENDOR_DEVICES) != 0) { + devices.addAll(mVendorDevices); + } return Collections.unmodifiableList(devices); } + private void initDevicesLists() { + boolean changed = initDefaultDevices(); + changed |= initVendorDevices(); + changed |= initUserDevices(); + if (changed) { + notifyListeners(); + } + } + /** - * Gets the {@link List} of {@link Device}s packaged with the SDK. - * - * @return The {@link List} of default {@link Device}s + * Initializes the {@link Device}s packaged with the SDK. + * @return True if the list has changed. */ - public List<Device> getDefaultDevices() { - synchronized (sLock) { + private boolean initDefaultDevices() { + synchronized (mLock) { if (mDefaultDevices == null) { try { mDefaultDevices = DeviceParser.parse( DeviceManager.class.getResourceAsStream(SdkConstants.FN_DEVICES_XML)); + return true; } catch (IllegalStateException e) { // The device builders can throw IllegalStateExceptions if // build gets called before everything is properly setup @@ -190,65 +230,64 @@ public class DeviceManager { mLog.error(null, "Error reading default devices"); mDefaultDevices = new ArrayList<Device>(); } - notifyListeners(); } } - return Collections.unmodifiableList(mDefaultDevices); + return false; } /** - * Returns all vendor-provided {@link Device}s - * - * @param sdkLocation Location of the Android SDK - * @return A list of vendor-provided {@link Device}s + * Initializes all vendor-provided {@link Device}s. + * @return True if the list has changed. */ - public List<Device> getVendorDevices(String sdkLocation) { - synchronized (sLock) { - if (mVendorDevices == null || !mVendorDevicesLocation.equals(sdkLocation)) { - mVendorDevicesLocation = sdkLocation; - List<Device> devices = new ArrayList<Device>(); - - // Load devices from tools folder - File toolsDevices = new File(sdkLocation, SdkConstants.OS_SDK_TOOLS_LIB_FOLDER + - File.separator + SdkConstants.FN_DEVICES_XML); - if (toolsDevices.isFile()) { - devices.addAll(loadDevices(toolsDevices)); - } + private boolean initVendorDevices() { + synchronized (mLock) { + if (mVendorDevices == null) { + mVendorDevices = new ArrayList<Device>(); + + if (mOsSdkPath != null) { + // Load devices from tools folder + File toolsDevices = new File(mOsSdkPath, + SdkConstants.OS_SDK_TOOLS_LIB_FOLDER + + File.separator + + SdkConstants.FN_DEVICES_XML); + if (toolsDevices.isFile()) { + mVendorDevices.addAll(loadDevices(toolsDevices)); + } - // Load devices from vendor extras - File extrasFolder = new File(sdkLocation, SdkConstants.FD_EXTRAS); - List<File> deviceDirs = getExtraDirs(extrasFolder); - for (File deviceDir : deviceDirs) { - File deviceXml = new File(deviceDir, SdkConstants.FN_DEVICES_XML); - if (deviceXml.isFile()) { - devices.addAll(loadDevices(deviceXml)); + // Load devices from vendor extras + File extrasFolder = new File(mOsSdkPath, SdkConstants.FD_EXTRAS); + List<File> deviceDirs = getExtraDirs(extrasFolder); + for (File deviceDir : deviceDirs) { + File deviceXml = new File(deviceDir, SdkConstants.FN_DEVICES_XML); + if (deviceXml.isFile()) { + mVendorDevices.addAll(loadDevices(deviceXml)); + } } + return true; } - mVendorDevices = devices; - notifyListeners(); } } - return Collections.unmodifiableList(mVendorDevices); + return false; } /** - * Returns all user-created {@link Device}s - * - * @return All user-created {@link Device}s + * Initializes all user-created {@link Device}s + * @return True if the list has changed. */ - public List<Device> getUserDevices() { - synchronized (sLock) { + private boolean initUserDevices() { + synchronized (mLock) { if (mUserDevices == null) { // User devices should be saved out to // $HOME/.android/devices.xml mUserDevices = new ArrayList<Device>(); File userDevicesFile = null; try { - userDevicesFile = new File(AndroidLocation.getFolder(), + userDevicesFile = new File( + AndroidLocation.getFolder(), SdkConstants.FN_DEVICES_XML); if (userDevicesFile.exists()) { mUserDevices.addAll(DeviceParser.parse(userDevicesFile)); - notifyListeners(); + return true; } } catch (AndroidLocationException e) { mLog.warning("Couldn't load user devices: %1$s", e.getMessage()); @@ -262,7 +301,8 @@ public class DeviceManager { renamedConfig = new File(base + '.' + (i++)); } mLog.error(null, "Error parsing %1$s, backing up to %2$s", - userDevicesFile.getAbsolutePath(), renamedConfig.getAbsolutePath()); + userDevicesFile.getAbsolutePath(), + renamedConfig.getAbsolutePath()); userDevicesFile.renameTo(renamedConfig); } } catch (ParserConfigurationException e) { @@ -274,42 +314,52 @@ public class DeviceManager { } } } - return Collections.unmodifiableList(mUserDevices); + return false; } public void addUserDevice(Device d) { - synchronized (sLock) { + boolean changed = false; + synchronized (mLock) { if (mUserDevices == null) { - getUserDevices(); + initUserDevices(); + assert mUserDevices != null; } - mUserDevices.add(d); + if (mUserDevices != null) { + mUserDevices.add(d); + } + changed = true; + } + if (changed) { + notifyListeners(); } - notifyListeners(); } public void removeUserDevice(Device d) { - synchronized (sLock) { + synchronized (mLock) { if (mUserDevices == null) { - getUserDevices(); + initUserDevices(); + assert mUserDevices != null; } - Iterator<Device> it = mUserDevices.iterator(); - while (it.hasNext()) { - Device userDevice = it.next(); - if (userDevice.getName().equals(d.getName()) - && userDevice.getManufacturer().equals(d.getManufacturer())) { - it.remove(); - notifyListeners(); - break; - } + if (mUserDevices != null) { + Iterator<Device> it = mUserDevices.iterator(); + while (it.hasNext()) { + Device userDevice = it.next(); + if (userDevice.getName().equals(d.getName()) + && userDevice.getManufacturer().equals(d.getManufacturer())) { + it.remove(); + notifyListeners(); + return; + } + } } } } public void replaceUserDevice(Device d) { - synchronized (sLock) { + synchronized (mLock) { if (mUserDevices == null) { - getUserDevices(); + initUserDevices(); } removeUserDevice(d); addUserDevice(d); @@ -339,7 +389,7 @@ public class DeviceManager { return; } - synchronized (sLock) { + synchronized (mLock) { if (mUserDevices.size() > 0) { try { DeviceWriter.writeToXml(new FileOutputStream(userDevicesFile), mUserDevices); @@ -446,8 +496,8 @@ public class DeviceManager { private void notifyListeners() { synchronized (sListeners) { - for (DevicesChangeListener listener : sListeners) { - listener.onDevicesChange(); + for (DevicesChangedListener listener : sListeners) { + listener.onDevicesChanged(); } } } @@ -483,7 +533,7 @@ public class DeviceManager { try { String line; while ((line = propertiesReader.readLine()) != null) { - Matcher m = sPathPropertyPattern.matcher(line); + Matcher m = PATH_PROPERTY_PATTERN.matcher(line); if (m.matches()) { return true; } diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/avd/AvdManager.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/avd/AvdManager.java index 6b219d3..5f35661 100644 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/avd/AvdManager.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/avd/AvdManager.java @@ -59,7 +59,7 @@ public class AvdManager { /** * Exception thrown when something is wrong with a target path. */ - private final static class InvalidTargetPathException extends Exception { + private static final class InvalidTargetPathException extends Exception { private static final long serialVersionUID = 1L; InvalidTargetPathException(String message) { @@ -69,26 +69,26 @@ public class AvdManager { public static final String AVD_FOLDER_EXTENSION = ".avd"; //$NON-NLS-1$ - public final static String AVD_INFO_PATH = "path"; //$NON-NLS-1$ - public final static String AVD_INFO_TARGET = "target"; //$NON-NLS-1$ + public static final String AVD_INFO_PATH = "path"; //$NON-NLS-1$ + public static final String AVD_INFO_TARGET = "target"; //$NON-NLS-1$ /** * AVD/config.ini key name representing the abi type of the specific avd * */ - public final static String AVD_INI_ABI_TYPE = "abi.type"; //$NON-NLS-1$ + public static final String AVD_INI_ABI_TYPE = "abi.type"; //$NON-NLS-1$ /** * AVD/config.ini key name representing the CPU architecture of the specific avd * */ - public final static String AVD_INI_CPU_ARCH = "hw.cpu.arch"; //$NON-NLS-1$ + public static final String AVD_INI_CPU_ARCH = "hw.cpu.arch"; //$NON-NLS-1$ /** * AVD/config.ini key name representing the CPU architecture of the specific avd * */ - public final static String AVD_INI_CPU_MODEL = "hw.cpu.model"; //$NON-NLS-1$ + public static final String AVD_INI_CPU_MODEL = "hw.cpu.model"; //$NON-NLS-1$ /** * AVD/config.ini key name representing the manufacturer of the device this avd was based on. @@ -106,19 +106,19 @@ public class AvdManager { * * @see #NUMERIC_SKIN_SIZE */ - public final static String AVD_INI_SKIN_PATH = "skin.path"; //$NON-NLS-1$ + public static final String AVD_INI_SKIN_PATH = "skin.path"; //$NON-NLS-1$ /** * 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 {@link #AVD_INI_SKIN_PATH} key instead. */ - public final static String AVD_INI_SKIN_NAME = "skin.name"; //$NON-NLS-1$ + public static final String AVD_INI_SKIN_NAME = "skin.name"; //$NON-NLS-1$ /** * AVD/config.ini key name representing whether a dynamic skin should be displayed. */ - public final static String AVD_INI_SKIN_DYNAMIC = "skin.dynamic"; //$NON-NLS-1$ + public static final String AVD_INI_SKIN_DYNAMIC = "skin.dynamic"; //$NON-NLS-1$ /** * AVD/config.ini key name representing the path to the sdcard file. @@ -127,7 +127,7 @@ public class AvdManager { * * @see #SDCARD_IMG */ - public final static String AVD_INI_SDCARD_PATH = "sdcard.path"; //$NON-NLS-1$ + public static final String AVD_INI_SDCARD_PATH = "sdcard.path"; //$NON-NLS-1$ /** * 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. @@ -135,7 +135,7 @@ public class AvdManager { * @see #SDCARD_SIZE_PATTERN * @see #parseSdcardSize(String, String[]) */ - public final static String AVD_INI_SDCARD_SIZE = "sdcard.size"; //$NON-NLS-1$ + public static final String AVD_INI_SDCARD_SIZE = "sdcard.size"; //$NON-NLS-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 @@ -143,80 +143,80 @@ public class AvdManager { * <p/> * The emulator looks at {@link #AVD_INI_IMAGES_1} before {@link #AVD_INI_IMAGES_2}. */ - public final static String AVD_INI_IMAGES_1 = "image.sysdir.1"; //$NON-NLS-1$ + public static final String AVD_INI_IMAGES_1 = "image.sysdir.1"; //$NON-NLS-1$ /** * 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 #AVD_INI_IMAGES_1 */ - public final static String AVD_INI_IMAGES_2 = "image.sysdir.2"; //$NON-NLS-1$ + public static final String AVD_INI_IMAGES_2 = "image.sysdir.2"; //$NON-NLS-1$ /** * 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 #SNAPSHOTS_IMG */ - public final static String AVD_INI_SNAPSHOT_PRESENT = "snapshot.present"; //$NON-NLS-1$ + public static final String AVD_INI_SNAPSHOT_PRESENT = "snapshot.present"; //$NON-NLS-1$ /** * AVD/config.ini key name representing whether hardware OpenGLES emulation is enabled */ - public final static String AVD_INI_GPU_EMULATION = "hw.gpu.enabled"; //$NON-NLS-1$ + public static final String AVD_INI_GPU_EMULATION = "hw.gpu.enabled"; //$NON-NLS-1$ /** * AVD/config.ini key name representing how to emulate the front facing camera */ - public final static String AVD_INI_CAMERA_FRONT = "hw.camera.front"; //$NON-NLS-1$ + public static final String AVD_INI_CAMERA_FRONT = "hw.camera.front"; //$NON-NLS-1$ /** * AVD/config.ini key name representing how to emulate the rear facing camera */ - public final static String AVD_INI_CAMERA_BACK = "hw.camera.back"; //$NON-NLS-1$ + public static final String AVD_INI_CAMERA_BACK = "hw.camera.back"; //$NON-NLS-1$ /** * AVD/config.ini key name representing the amount of RAM the emulated device should have */ - public final static String AVD_INI_RAM_SIZE = "hw.ramSize"; + public static final String AVD_INI_RAM_SIZE = "hw.ramSize"; /** * AVD/config.ini key name representing the amount of memory available to applications by default */ - public final static String AVD_INI_VM_HEAP_SIZE = "vm.heapSize"; + public static final String AVD_INI_VM_HEAP_SIZE = "vm.heapSize"; /** * AVD/config.ini key name representing the size of the data partition */ - public final static String AVD_INI_DATA_PARTITION_SIZE = "disk.dataPartition.size"; + public static final String AVD_INI_DATA_PARTITION_SIZE = "disk.dataPartition.size"; /** * AVD/config.ini key name representing the hash of the device this AVD is based on */ - public final static String AVD_INI_DEVICE_HASH = "hw.device.hash"; + public static final String AVD_INI_DEVICE_HASH = "hw.device.hash"; /** * Pattern to match pixel-sized skin "names", e.g. "320x480". */ - public final static Pattern NUMERIC_SKIN_SIZE = Pattern.compile("([0-9]{2,})x([0-9]{2,})"); //$NON-NLS-1$ + public static final Pattern NUMERIC_SKIN_SIZE = Pattern.compile("([0-9]{2,})x([0-9]{2,})"); //$NON-NLS-1$ - private final static String USERDATA_IMG = "userdata.img"; //$NON-NLS-1$ - final static String CONFIG_INI = "config.ini"; //$NON-NLS-1$ - private final static String SDCARD_IMG = "sdcard.img"; //$NON-NLS-1$ - private final static String SNAPSHOTS_IMG = "snapshots.img"; //$NON-NLS-1$ + private static final String USERDATA_IMG = "userdata.img"; //$NON-NLS-1$ + static final String CONFIG_INI = "config.ini"; //$NON-NLS-1$ + private static final String SDCARD_IMG = "sdcard.img"; //$NON-NLS-1$ + private static final String SNAPSHOTS_IMG = "snapshots.img"; //$NON-NLS-1$ - final static String INI_EXTENSION = ".ini"; //$NON-NLS-1$ - private final static Pattern INI_NAME_PATTERN = Pattern.compile("(.+)\\" + //$NON-NLS-1$ + static final String INI_EXTENSION = ".ini"; //$NON-NLS-1$ + private static final Pattern INI_NAME_PATTERN = Pattern.compile("(.+)\\" + //$NON-NLS-1$ INI_EXTENSION + "$", //$NON-NLS-1$ Pattern.CASE_INSENSITIVE); - private final static Pattern IMAGE_NAME_PATTERN = Pattern.compile("(.+)\\.img$", //$NON-NLS-1$ + private static final Pattern IMAGE_NAME_PATTERN = Pattern.compile("(.+)\\.img$", //$NON-NLS-1$ Pattern.CASE_INSENSITIVE); /** * Pattern for matching SD Card sizes, e.g. "4K" or "16M". * Callers should use {@link #parseSdcardSize(String, String[])} instead of using this directly. */ - private final static Pattern SDCARD_SIZE_PATTERN = Pattern.compile("(\\d+)([KMG])"); //$NON-NLS-1$ + private static final Pattern SDCARD_SIZE_PATTERN = Pattern.compile("(\\d+)([KMG])"); //$NON-NLS-1$ /** * Minimal size of an SDCard image file in bytes. Currently 9 MiB. @@ -229,19 +229,19 @@ public class AvdManager { public static final long SDCARD_MAX_BYTE_SIZE = 1023L<<30; /** The sdcard string represents a valid number but the size is outside of the allowed range. */ - public final static int SDCARD_SIZE_NOT_IN_RANGE = 0; + public static final int SDCARD_SIZE_NOT_IN_RANGE = 0; /** The sdcard string looks like a size number+suffix but the number failed to decode. */ - public final static int SDCARD_SIZE_INVALID = -1; + public static final int SDCARD_SIZE_INVALID = -1; /** The sdcard string doesn't look like a size, it might be a path instead. */ - public final static int SDCARD_NOT_SIZE_PATTERN = -2; + public static final int SDCARD_NOT_SIZE_PATTERN = -2; /** Regex used to validate characters that compose an AVD name. */ - public final static Pattern RE_AVD_NAME = Pattern.compile("[a-zA-Z0-9._-]+"); //$NON-NLS-1$ + public static final Pattern RE_AVD_NAME = Pattern.compile("[a-zA-Z0-9._-]+"); //$NON-NLS-1$ /** List of valid characters for an AVD name. Used for display purposes. */ - public final static String CHARS_AVD_NAME = "a-z A-Z 0-9 . _ -"; //$NON-NLS-1$ + public static final String CHARS_AVD_NAME = "a-z A-Z 0-9 . _ -"; //$NON-NLS-1$ - public final static String HARDWARE_INI = "hardware.ini"; //$NON-NLS-1$ + public static final String HARDWARE_INI = "hardware.ini"; //$NON-NLS-1$ /** * Status returned by {@link AvdManager#isAvdNameConflicting(String)}. @@ -1410,8 +1410,8 @@ public class AvdManager { String hash = properties.get(AVD_INI_DEVICE_HASH); if (deviceName != null && deviceMfctr != null && hash != null) { int deviceHash = Integer.parseInt(hash); - deviceStatus = (new DeviceManager(log)).getDeviceStatus( - mSdkManager.getLocation(), deviceName, deviceMfctr, deviceHash); + DeviceManager devMan = DeviceManager.createInstance(mSdkManager.getLocation(), log); + deviceStatus = devMan.getDeviceStatus(deviceName, deviceMfctr, deviceHash); } } diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/ui/AvdManagerPage.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/ui/AvdManagerPage.java index 4d7e79e..a092550 100755 --- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/ui/AvdManagerPage.java +++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/ui/AvdManagerPage.java @@ -18,7 +18,7 @@ package com.android.sdkuilib.internal.repository.ui; import com.android.prefs.AndroidLocation.AndroidLocationException; import com.android.sdklib.devices.DeviceManager; -import com.android.sdklib.devices.DeviceManager.DevicesChangeListener; +import com.android.sdklib.devices.DeviceManager.DevicesChangedListener; import com.android.sdklib.internal.avd.AvdInfo; import com.android.sdklib.internal.avd.AvdManager; import com.android.sdkuilib.internal.repository.UpdaterData; @@ -44,7 +44,7 @@ import org.eclipse.swt.widgets.Label; * page displays the actually list of AVDs and various action buttons. */ public class AvdManagerPage extends Composite - implements ISdkChangeListener, DevicesChangeListener, DisposeListener { + implements ISdkChangeListener, DevicesChangedListener, DisposeListener { private AvdSelector mAvdSelector; @@ -162,7 +162,7 @@ public class AvdManagerPage extends Composite // --- Implementation of DevicesChangeListener @Override - public void onDevicesChange() { + public void onDevicesChanged() { mAvdSelector.refresh(false /*reload*/); } diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/ui/AvdManagerWindowImpl1.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/ui/AvdManagerWindowImpl1.java index 08eed1b..e3efca6 100755 --- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/ui/AvdManagerWindowImpl1.java +++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/ui/AvdManagerWindowImpl1.java @@ -94,7 +94,7 @@ public class AvdManagerWindowImpl1 { mContext = context; mUpdaterData = new UpdaterData(osSdkRoot, sdkLog); mOwnUpdaterData = true; - mDeviceManager = new DeviceManager(sdkLog); + mDeviceManager = DeviceManager.createInstance(osSdkRoot, sdkLog); } /** @@ -116,7 +116,8 @@ public class AvdManagerWindowImpl1 { mContext = context; mUpdaterData = updaterData; mOwnUpdaterData = false; - mDeviceManager = new DeviceManager(mUpdaterData.getSdkLog()); + mDeviceManager = DeviceManager.createInstance(mUpdaterData.getOsSdkRoot(), + mUpdaterData.getSdkLog()); } /** diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/ui/DeviceManagerPage.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/ui/DeviceManagerPage.java index 6bac1ba..7b63d39 100755 --- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/ui/DeviceManagerPage.java +++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/ui/DeviceManagerPage.java @@ -18,7 +18,7 @@ package com.android.sdkuilib.internal.repository.ui; import com.android.sdklib.devices.Device; import com.android.sdklib.devices.DeviceManager; -import com.android.sdklib.devices.DeviceManager.DevicesChangeListener; +import com.android.sdklib.devices.DeviceManager.DevicesChangedListener; import com.android.sdklib.devices.Hardware; import com.android.sdklib.devices.Screen; import com.android.sdklib.devices.Storage; @@ -88,7 +88,7 @@ import java.util.regex.Pattern; * - a filter box to do a string search on any part of the display. */ public class DeviceManagerPage extends Composite - implements ISdkChangeListener, DevicesChangeListener, DisposeListener { + implements ISdkChangeListener, DevicesChangedListener, DisposeListener { public interface IAvdCreatedListener { public void onAvdCreated(AvdInfo createdAvdInfo); @@ -355,11 +355,10 @@ public class DeviceManagerPage extends Composite try { mDisableRefresh = true; disposables.addAll(fillDevices(table, boldFont, true, - mDeviceManager.getUserDevices(), - null)); + mDeviceManager.getDevices(DeviceManager.USER_DEVICES))); disposables.addAll(fillDevices(table, boldFont, false, - mDeviceManager.getDefaultDevices(), - mDeviceManager.getVendorDevices(mUpdaterData.getOsSdkRoot()))); + mDeviceManager.getDevices(DeviceManager.DEFAULT_DEVICES | + DeviceManager.VENDOR_DEVICES))); } finally { mDisableRefresh = false; } @@ -456,19 +455,15 @@ public class DeviceManagerPage extends Composite Table table, Font boldFont, boolean isUser, - List<Device> devices1, - List<Device> devices2) { + List<Device> devices) { List<Resource> disposables = new ArrayList<Resource>(); Display display = table.getDisplay(); TextStyle boldStyle = new TextStyle(); boldStyle.font = boldFont; - - List<Device> devices = new ArrayList<Device>(devices1); - if (devices2 != null) { - devices.addAll(devices2); - } + // We need the list to be be modifiable so that we can sort it. + devices = new ArrayList<Device>(devices); if (isUser) { // Just sort user devices by alphabetical name. They will show up at the top. @@ -582,15 +577,14 @@ public class DeviceManagerPage extends Composite } // Constants extracted from DeviceMenuListerner -- TODO refactor somewhere else. - @SuppressWarnings("unused") - private static final String NEXUS = "Nexus"; //$NON-NLS-1$ + private static final String NEXUS = "Nexus"; //$NON-NLS-1$ private static final String GENERIC = "Generic"; //$NON-NLS-1$ private static Pattern PATTERN = Pattern.compile( "(\\d+\\.?\\d*)in (.+?)( \\(.*Nexus.*\\))?"); //$NON-NLS-1$ /** * Returns a pretty name for the device. * - * Extracted from DeviceMenuListerner. + * Extracted from DeviceMenuListener. * Modified to remove the leading space insertion as it doesn't render * neatly in the avd manager. Instead added the option to add leading * zeroes to make the string names sort properly. @@ -828,7 +822,7 @@ public class DeviceManagerPage extends Composite // --- Implementation of DevicesChangeListener @Override - public void onDevicesChange() { + public void onDevicesChanged() { onRefresh(); } diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/AvdCreationDialog.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/AvdCreationDialog.java index 5d2a264..e88b3e8 100644 --- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/AvdCreationDialog.java +++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/AvdCreationDialog.java @@ -461,8 +461,8 @@ public class AvdCreationDialog extends GridDialog { SdkManager sdkManager = mAvdManager.getSdkManager(); String location = sdkManager.getLocation(); if (sdkManager != null && location != null) { - DeviceManager deviceManager = new DeviceManager(mSdkLog); - List<Device> deviceList = new ArrayList<Device>(deviceManager.getDevices(location)); + DeviceManager deviceManager = DeviceManager.createInstance(location, mSdkLog); + List<Device> deviceList = deviceManager.getDevices(DeviceManager.ALL_DEVICES); // Sort List<Device> nexus = new ArrayList<Device>(deviceList.size()); @@ -608,6 +608,9 @@ public class AvdCreationDialog extends GridDialog { case XHIGH: case XXHIGH: vmHeapSize = 128; + break; + case NODPI: + break; } } else { switch (density) { @@ -622,7 +625,9 @@ public class AvdCreationDialog extends GridDialog { case XHIGH: case XXHIGH: vmHeapSize = 64; - + break; + case NODPI: + break; } } mVmHeap.setText(Integer.toString(vmHeapSize)); @@ -734,6 +739,8 @@ public class AvdCreationDialog extends GridDialog { } } + @SuppressWarnings("unused") + @Deprecated // FIXME unused, cleanup later private IAndroidTarget getSelectedTarget() { IAndroidTarget[] targets = (IAndroidTarget[]) mTarget.getData(); int index = mTarget.getSelectionIndex(); diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/AvdSelector.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/AvdSelector.java index 42d85eb..67d161f 100644 --- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/AvdSelector.java +++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/AvdSelector.java @@ -115,6 +115,8 @@ public final class AvdSelector { private final ILogger mSdkLog; + private boolean mInternalRefresh; + /** * The display mode of the AVD Selector. @@ -467,21 +469,29 @@ public final class AvdSelector { * <code>false</code>. */ public boolean refresh(boolean reload) { - if (reload) { + if (!mInternalRefresh) { try { - mAvdManager.reloadAvds(NullLogger.getLogger()); - } catch (AndroidLocationException e) { - return false; + // Note that AvdManagerPage.onDevicesChange() will trigger a + // refresh while the AVDs are being reloaded so prevent from + // having a recursive call to here. + mInternalRefresh = true; + if (reload) { + try { + mAvdManager.reloadAvds(NullLogger.getLogger()); + } catch (AndroidLocationException e) { + return false; + } + } + + AvdInfo selected = getSelected(); + fillTable(mTable); + setSelection(selected); + return true; + } finally { + mInternalRefresh = false; } } - - AvdInfo selected = getSelected(); - - fillTable(mTable); - - setSelection(selected); - - return true; + return false; } /** @@ -1021,7 +1031,8 @@ public final class AvdSelector { // Overwrite the properties derived from the device and nothing else Map<String, String> properties = new HashMap<String, String>(avdInfo.getProperties()); - List<Device> devices = (new DeviceManager(mSdkLog)).getDevices(mOsSdkPath); + DeviceManager devMan = DeviceManager.createInstance(mOsSdkPath, mSdkLog); + List<Device> devices = devMan.getDevices(DeviceManager.ALL_DEVICES); String name = properties.get(AvdManager.AVD_INI_DEVICE_NAME); String manufacturer = properties.get(AvdManager.AVD_INI_DEVICE_MANUFACTURER); diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/AvdStartDialog.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/AvdStartDialog.java index 0c68dcf..925b0cd 100644 --- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/AvdStartDialog.java +++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/AvdStartDialog.java @@ -100,7 +100,7 @@ final class AvdStartDialog extends GridDialog { mAvd = avd; mSdkLocation = sdkLocation; mSettingsController = settingsController; - mDeviceManager = new DeviceManager(sdkLog); + mDeviceManager = DeviceManager.createInstance(mSdkLocation, sdkLog); if (mAvd == null) { throw new IllegalArgumentException("avd cannot be null"); } @@ -449,7 +449,7 @@ final class AvdStartDialog extends GridDialog { String name = properties.get(AvdManager.AVD_INI_DEVICE_NAME); String mfctr = properties.get(AvdManager.AVD_INI_DEVICE_MANUFACTURER); if (name != null && mfctr != null) { - Device d = mDeviceManager.getDevice(mSdkLocation, name, mfctr); + Device d = mDeviceManager.getDevice(name, mfctr); if (d != null) { double screenSize = d.getDefaultHardware().getScreen().getDiagonalLength(); diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/DeviceCreationDialog.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/DeviceCreationDialog.java index 0707ddc..68c4fd5 100644 --- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/DeviceCreationDialog.java +++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/DeviceCreationDialog.java @@ -143,7 +143,7 @@ public class DeviceCreationDialog extends GridDialog { mImageFactory = imageFactory; mDevice = device; mManager = manager; - mUserDevices = mManager.getUserDevices(); + mUserDevices = mManager.getDevices(DeviceManager.USER_DEVICES); } /** |