aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/Sdk.java2
-rw-r--r--sdkmanager/app/src/com/android/sdkmanager/Main.java10
-rw-r--r--sdkmanager/libs/sdklib/src/com/android/sdklib/internal/avd/AvdManager.java23
-rwxr-xr-xsdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterData.java2
4 files changed, 29 insertions, 8 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/Sdk.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/Sdk.java
index bcca729..6b45f09 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/Sdk.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/Sdk.java
@@ -270,7 +270,7 @@ public final class Sdk {
// create the AVD Manager
AvdManager avdManager = null;
try {
- avdManager = new AvdManager(manager, log);
+ avdManager = AvdManager.getInstance(manager, log);
} catch (AndroidLocationException e) {
log.error(e, "Error parsing the AVDs");
}
diff --git a/sdkmanager/app/src/com/android/sdkmanager/Main.java b/sdkmanager/app/src/com/android/sdkmanager/Main.java
index bbfbdcc..3d08574 100644
--- a/sdkmanager/app/src/com/android/sdkmanager/Main.java
+++ b/sdkmanager/app/src/com/android/sdkmanager/Main.java
@@ -1007,7 +1007,7 @@ public class Main {
*/
private void displayAvdList() {
try {
- AvdManager avdManager = new AvdManager(mSdkManager, mSdkLog);
+ AvdManager avdManager = AvdManager.getInstance(mSdkManager, mSdkLog);
displayAvdList(avdManager);
} catch (AndroidLocationException e) {
errorAndExit(e.getMessage());
@@ -1031,7 +1031,7 @@ public class Main {
try {
boolean removePrevious = mSdkCommandLine.getFlagForce();
- AvdManager avdManager = new AvdManager(mSdkManager, mSdkLog);
+ AvdManager avdManager = AvdManager.getInstance(mSdkManager, mSdkLog);
String avdName = mSdkCommandLine.getParamName();
@@ -1157,7 +1157,7 @@ public class Main {
private void deleteAvd() {
try {
String avdName = mSdkCommandLine.getParamName();
- AvdManager avdManager = new AvdManager(mSdkManager, mSdkLog);
+ AvdManager avdManager = AvdManager.getInstance(mSdkManager, mSdkLog);
AvdInfo info = avdManager.getAvd(avdName, false /*validAvdOnly*/);
if (info == null) {
@@ -1177,7 +1177,7 @@ public class Main {
private void moveAvd() {
try {
String avdName = mSdkCommandLine.getParamName();
- AvdManager avdManager = new AvdManager(mSdkManager, mSdkLog);
+ AvdManager avdManager = AvdManager.getInstance(mSdkManager, mSdkLog);
AvdInfo info = avdManager.getAvd(avdName, true /*validAvdOnly*/);
if (info == null) {
@@ -1273,7 +1273,7 @@ public class Main {
private void updateAvd() {
try {
String avdName = mSdkCommandLine.getParamName();
- AvdManager avdManager = new AvdManager(mSdkManager, mSdkLog);
+ AvdManager avdManager = AvdManager.getInstance(mSdkManager, mSdkLog);
avdManager.updateAvd(avdName, mSdkLog);
} catch (AndroidLocationException e) {
errorAndExit(e.getMessage());
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 16bbb38..46d3124 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
@@ -41,9 +41,11 @@ import java.io.FilenameFilter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.WeakHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -215,6 +217,12 @@ public class AvdManager {
CONFLICT_EXISTING_PATH,
}
+ // A map where the keys are the locations of the SDK and the values are the corresponding
+ // AvdManagers. This prevents us from creating multiple AvdManagers for the same SDK and having
+ // them get out of sync.
+ private static final Map<String, AvdManager> mManagers =
+ Collections.synchronizedMap(new WeakHashMap<String, AvdManager>());
+
private final ArrayList<AvdInfo> mAllAvdList = new ArrayList<AvdInfo>();
private AvdInfo[] mValidAvdList;
private AvdInfo[] mBrokenAvdList;
@@ -230,11 +238,24 @@ public class AvdManager {
* logging needs. Cannot be null.
* @throws AndroidLocationException
*/
- public AvdManager(SdkManager sdkManager, ISdkLog log) throws AndroidLocationException {
+ protected AvdManager(SdkManager sdkManager, ISdkLog log) throws AndroidLocationException {
mSdkManager = sdkManager;
buildAvdList(mAllAvdList, log);
}
+ public static AvdManager getInstance(SdkManager sdkManager, ISdkLog log)
+ throws AndroidLocationException {
+ synchronized(mManagers) {
+ AvdManager manager;
+ if ((manager = mManagers.get(sdkManager.getLocation())) != null) {
+ return manager;
+ }
+ manager = new AvdManager(sdkManager, log);
+ mManagers.put(sdkManager.getLocation(), manager);
+ return manager;
+ }
+ }
+
/**
* Returns the base folder where AVDs are created.
*
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterData.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterData.java
index 3361b77..6b3fcac 100755
--- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterData.java
+++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterData.java
@@ -259,7 +259,7 @@ public class UpdaterData implements IUpdaterData {
setSdkManager(SdkManager.createManager(mOsSdkRoot, mSdkLog));
try {
mAvdManager = null;
- mAvdManager = new AvdManager(mSdkManager, mSdkLog);
+ mAvdManager = AvdManager.getInstance(mSdkManager, mSdkLog);
} catch (AndroidLocationException e) {
mSdkLog.error(e, "Unable to read AVDs: " + e.getMessage()); //$NON-NLS-1$