aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaphael Moll <ralf@android.com>2010-04-21 15:32:40 -0700
committerRaphael Moll <ralf@android.com>2010-04-22 19:17:38 -0700
commit06f1db5f1e0dc01f7a318b2fabbbd24f00823ca3 (patch)
tree6cf587ccf203e283e729ac96110b388f6088c904
parent353e797d2ffed5a653c0eab0d0756d59c1945d1e (diff)
downloadsdk-06f1db5f1e0dc01f7a318b2fabbbd24f00823ca3.zip
sdk-06f1db5f1e0dc01f7a318b2fabbbd24f00823ca3.tar.gz
sdk-06f1db5f1e0dc01f7a318b2fabbbd24f00823ca3.tar.bz2
Fix auto launch config to respect minSdkVersion
When launch config is in automatic mode with no preferred AVD and minSdkVersion is smaller than the project targert's API level, try to find an AVD that's as close to the minSdkVersion as possible. SDK Bug http://b.android.com/7897 Change-Id: Ied1f2db8f61c27430b466b2b7afbb5494fd0ffed
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/AndroidLaunchController.java47
1 files changed, 45 insertions, 2 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/AndroidLaunchController.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/AndroidLaunchController.java
index 4c8621e..2f959ff 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/AndroidLaunchController.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/AndroidLaunchController.java
@@ -313,7 +313,7 @@ public final class AndroidLaunchController implements IDebugBridgeChangeListener
}
// get the project target
- final IAndroidTarget projectTarget = currentSdk.getTarget(project);
+ IAndroidTarget projectTarget = currentSdk.getTarget(project);
// FIXME: check errors on missing sdk, AVD manager, or project target.
@@ -358,6 +358,7 @@ public final class AndroidLaunchController implements IDebugBridgeChangeListener
if (preferredAvd != null) {
// look for a matching device
+
for (IDevice d : devices) {
String deviceAvd = d.getAvdName();
if (deviceAvd != null && deviceAvd.equals(config.mAvdName)) {
@@ -385,6 +386,47 @@ public final class AndroidLaunchController implements IDebugBridgeChangeListener
}
// no (valid) preferred AVD? look for one.
+
+ // If the API level requested in the manifest is lower than the current project
+ // target, when we will iterate devices/avds later ideally we will want to find
+ // a device/avd which target is as close to the manifest as possible (instead of
+ // a device which target is the same as the project's target) and use it as the
+ // new default.
+
+ int reqApiLevel = 0;
+ try {
+ reqApiLevel = Integer.parseInt(requiredApiVersionNumber);
+
+ if (reqApiLevel > 0 && reqApiLevel < projectTarget.getVersion().getApiLevel()) {
+ int maxDist = projectTarget.getVersion().getApiLevel() - reqApiLevel;
+ IAndroidTarget candidate = null;
+
+ for (IAndroidTarget target : currentSdk.getTargets()) {
+ if (target.canRunOn(projectTarget)) {
+ int currDist = target.getVersion().getApiLevel() - reqApiLevel;
+ if (currDist >= 0 && currDist < maxDist) {
+ maxDist = currDist;
+ candidate = target;
+ if (maxDist == 0) {
+ // Found a perfect match
+ break;
+ }
+ }
+ }
+ }
+
+ if (candidate != null) {
+ // We found a better SDK target candidate, that is closer to the
+ // API level from minSdkVersion than the one currently used by the
+ // project. Below (in the for...devices loop) we'll try to find
+ // a device/AVD for it.
+ projectTarget = candidate;
+ }
+ }
+ } catch (NumberFormatException e) {
+ // pass
+ }
+
HashMap<IDevice, AvdInfo> compatibleRunningAvds = new HashMap<IDevice, AvdInfo>();
boolean hasDevice = false; // if there's 1+ device running, we may force manual mode,
// as we cannot always detect proper compatibility with
@@ -507,6 +549,7 @@ public final class AndroidLaunchController implements IDebugBridgeChangeListener
}
// bring up the device chooser.
+ final IAndroidTarget desiredProjectTarget = projectTarget;
AdtPlugin.getDisplay().asyncExec(new Runnable() {
public void run() {
try {
@@ -514,7 +557,7 @@ public final class AndroidLaunchController implements IDebugBridgeChangeListener
// or the AVD to launch.
DeviceChooserDialog dialog = new DeviceChooserDialog(
AdtPlugin.getDisplay().getActiveShell(),
- response, launchInfo.getPackageName(), projectTarget);
+ response, launchInfo.getPackageName(), desiredProjectTarget);
if (dialog.open() == Dialog.OK) {
AndroidLaunchController.this.continueLaunch(response, project, launch,
launchInfo, config);