aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSiva Velusamy <vsiva@google.com>2013-12-18 17:15:44 -0800
committerSiva Velusamy <vsiva@google.com>2013-12-18 17:27:08 -0800
commitd43a349cecbf4c35b5d7286af4fe34a0a5aa693e (patch)
tree7eb1217627cddd8b98ac23f5722b3d1bc2d911eb
parent7df33289af057cf53b89bcc52c97dd451989fcbd (diff)
downloadsdk-d43a349cecbf4c35b5d7286af4fe34a0a5aa693e.tar.gz
Allow control over whether Device Chooser Dialog is displayed
This CL allows users to control whether the device chooser dialog will be displayed during a launch. Currently, when performing a launch, the chooser dialog is displayed. It has a checkbox for users to indicate that the same selected device should be used for further launches. However, once set, there was no way that the setting could be overridden to show the dialog again. This CL mirrors that checkbox in the launch configuration. This allows users to modify the launch configuration and disable the "Use last selected device" checkbox, thereby forcing the chooser dialog to be displayed again. Fixes https://code.google.com/p/android/issues/detail?id=56076 Change-Id: I19dce8dd3acb76e799a422568267f28318b5ef58
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/AndroidLaunchConfiguration.java15
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/AndroidLaunchController.java78
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/DeviceChoiceCache.java79
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/DeviceChooserDialog.java14
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/EmulatorConfigTab.java56
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/LaunchConfigDelegate.java8
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.ndk/src/com/android/ide/eclipse/ndk/internal/launch/NdkGdbLaunchDelegate.java37
7 files changed, 149 insertions, 138 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/AndroidLaunchConfiguration.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/AndroidLaunchConfiguration.java
index df30879ae..580bbbee5 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/AndroidLaunchConfiguration.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/AndroidLaunchConfiguration.java
@@ -94,6 +94,12 @@ public class AndroidLaunchConfiguration {
*/
public String mEmulatorCommandLine;
+ /** Flag indicating whether the same device should be used for future launches. */
+ public boolean mReuseLastUsedDevice = false;
+
+ /** Serial number of the device used in the last launch of this config. */
+ public String mLastUsedDevice = null;
+
/**
* Initialized the structure from an ILaunchConfiguration object.
* @param config
@@ -109,6 +115,15 @@ public class AndroidLaunchConfiguration {
mTargetMode = parseTargetMode(config, mTargetMode);
try {
+ mReuseLastUsedDevice = config.getAttribute(
+ LaunchConfigDelegate.ATTR_REUSE_LAST_USED_DEVICE, false);
+ mLastUsedDevice = config.getAttribute(
+ LaunchConfigDelegate.ATTR_LAST_USED_DEVICE, (String)null);
+ } catch (CoreException e) {
+ // nothing to be done here, we'll use the default value
+ }
+
+ try {
mAvdName = config.getAttribute(LaunchConfigDelegate.ATTR_AVD_NAME, mAvdName);
} catch (CoreException e) {
// ignore
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 6ac3385e7..a95ed6882 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
@@ -16,6 +16,8 @@
package com.android.ide.eclipse.adt.internal.launch;
+import com.android.annotations.NonNull;
+import com.android.annotations.Nullable;
import com.android.ddmlib.AdbCommandRejectedException;
import com.android.ddmlib.AndroidDebugBridge;
import com.android.ddmlib.AndroidDebugBridge.IClientChangeListener;
@@ -361,12 +363,15 @@ public final class AndroidLaunchController implements IDebugBridgeChangeListener
* the app (by api level), and launch on all the others.
*/
IDevice[] devices = AndroidDebugBridge.getBridge().getDevices();
- IDevice deviceUsedInLastLaunch = DeviceChoiceCache.get(
- launch.getLaunchConfiguration().getName());
- if (deviceUsedInLastLaunch != null) {
- response.setDeviceToUse(deviceUsedInLastLaunch);
- continueLaunch(response, project, launch, launchInfo, config);
- return;
+ if (config.mReuseLastUsedDevice) {
+ // check to see if the last used device is still online
+ IDevice lastUsedDevice = getDeviceIfOnline(config.mLastUsedDevice,
+ devices);
+ if (lastUsedDevice != null) {
+ response.setDeviceToUse(lastUsedDevice);
+ continueLaunch(response, project, launch, launchInfo, config);
+ return;
+ }
}
if (config.mTargetMode == TargetMode.AUTO) {
@@ -611,9 +616,11 @@ public final class AndroidLaunchController implements IDebugBridgeChangeListener
DeviceChooserDialog dialog = new DeviceChooserDialog(
AdtPlugin.getShell(),
response, launchInfo.getPackageName(),
- desiredProjectTarget, minApiVersion);
+ desiredProjectTarget, minApiVersion,
+ config.mReuseLastUsedDevice);
if (dialog.open() == Dialog.OK) {
- DeviceChoiceCache.put(launch.getLaunchConfiguration().getName(), response);
+ updateLaunchConfigWithLastUsedDevice(launch.getLaunchConfiguration(),
+ response);
continueLaunch.set(true);
} else {
AdtPlugin.printErrorToConsole(project, "Launch canceled!");
@@ -1807,4 +1814,59 @@ public final class AndroidLaunchController implements IDebugBridgeChangeListener
mWaitingForDebuggerApplications.remove(launchInfo);
}
}
+
+ public static void updateLaunchConfigWithLastUsedDevice(
+ ILaunchConfiguration launchConfiguration, DeviceChooserResponse response) {
+ try {
+ boolean configModified = false;
+ boolean reuse = launchConfiguration.getAttribute(
+ LaunchConfigDelegate.ATTR_REUSE_LAST_USED_DEVICE, false);
+ String serial = launchConfiguration.getAttribute(
+ LaunchConfigDelegate.ATTR_LAST_USED_DEVICE, (String)null);
+
+ ILaunchConfigurationWorkingCopy wc = launchConfiguration.getWorkingCopy();
+ if (reuse != response.useDeviceForFutureLaunches()) {
+ reuse = response.useDeviceForFutureLaunches();
+ wc.setAttribute(LaunchConfigDelegate.ATTR_REUSE_LAST_USED_DEVICE, reuse);
+ configModified = true;
+ }
+
+ if (reuse) {
+ String selected = getSerial(response);
+ if (selected != null && !selected.equalsIgnoreCase(serial)) {
+ wc.setAttribute(LaunchConfigDelegate.ATTR_LAST_USED_DEVICE, selected);
+ configModified = true;
+ }
+ }
+
+ if (configModified) {
+ wc.doSave();
+ }
+ } catch (CoreException e) {
+ // in such a case, users just won't see this setting take effect
+ return;
+ }
+ }
+
+ private static String getSerial(DeviceChooserResponse response) {
+ AvdInfo avd = response.getAvdToLaunch();
+ return (avd != null) ? avd.getName() : response.getDeviceToUse().getSerialNumber();
+ }
+
+ @Nullable
+ public static IDevice getDeviceIfOnline(@Nullable String serial,
+ @NonNull IDevice[] onlineDevices) {
+ if (serial == null) {
+ return null;
+ }
+
+ for (IDevice device : onlineDevices) {
+ if (serial.equals(device.getAvdName()) ||
+ serial.equals(device.getSerialNumber())) {
+ return device;
+ }
+ }
+
+ return null;
+ }
}
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/DeviceChoiceCache.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/DeviceChoiceCache.java
deleted file mode 100644
index ecf596d33..000000000
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/DeviceChoiceCache.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Eclipse Public License, Version 1.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.eclipse.org/org/documents/epl-v10.php
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.ide.eclipse.adt.internal.launch;
-
-import com.android.ddmlib.AndroidDebugBridge;
-import com.android.ddmlib.IDevice;
-import com.android.ide.eclipse.adt.internal.launch.DeviceChooserDialog.DeviceChooserResponse;
-import com.android.sdklib.internal.avd.AvdInfo;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * {@link DeviceChoiceCache} maps a launch configuration name to the device selected for use
- * in that launch configuration by the {@link DeviceChooserDialog}.
- */
-public class DeviceChoiceCache {
- private static final Map<String, String> sDeviceUsedForLaunch = new HashMap<String, String>();
-
- public static IDevice get(String launchConfigName) {
- // obtain the cached entry
- String deviceName = sDeviceUsedForLaunch.get(launchConfigName);
- if (deviceName == null) {
- return null;
- }
-
- // verify that the device is still online
- for (IDevice device : getOnlineDevices()) {
- if (deviceName.equals(device.getAvdName()) ||
- deviceName.equals(device.getSerialNumber())) {
- return device;
- }
- }
-
- // remove from cache if device is not online anymore
- sDeviceUsedForLaunch.remove(launchConfigName);
-
- return null;
- }
-
- public static void put(String launchConfigName, DeviceChooserResponse response) {
- if (!response.useDeviceForFutureLaunches()) {
- return;
- }
-
- AvdInfo avd = response.getAvdToLaunch();
- String device = null;
- if (avd != null) {
- device = avd.getName();
- } else {
- device = response.getDeviceToUse().getSerialNumber();
- }
-
- sDeviceUsedForLaunch.put(launchConfigName, device);
- }
-
- private static IDevice[] getOnlineDevices() {
- AndroidDebugBridge bridge = AndroidDebugBridge.getBridge();
- if (bridge != null) {
- return bridge.getDevices();
- } else {
- return new IDevice[0];
- }
- }
-}
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/DeviceChooserDialog.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/DeviceChooserDialog.java
index 10dcd01de..1b850c9b7 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/DeviceChooserDialog.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/DeviceChooserDialog.java
@@ -88,7 +88,7 @@ public class DeviceChooserDialog extends Dialog implements IDeviceChangeListener
private Button mDeviceRadioButton;
private Button mUseDeviceForFutureLaunchesCheckbox;
- private static boolean sUseDeviceForFutureLaunchesValue = false;
+ private boolean mUseDeviceForFutureLaunches;
private boolean mDisableAvdSelectionChange = false;
@@ -284,7 +284,8 @@ public class DeviceChooserDialog extends Dialog implements IDeviceChangeListener
}
public DeviceChooserDialog(Shell parent, DeviceChooserResponse response, String packageName,
- IAndroidTarget projectTarget, AndroidVersion minApiVersion) {
+ IAndroidTarget projectTarget, AndroidVersion minApiVersion,
+ boolean useDeviceForFutureLaunches) {
super(parent);
mResponse = response;
@@ -292,6 +293,7 @@ public class DeviceChooserDialog extends Dialog implements IDeviceChangeListener
mProjectTarget = projectTarget;
mMinApiVersion = minApiVersion;
mSdk = Sdk.getCurrent();
+ mUseDeviceForFutureLaunches = useDeviceForFutureLaunches;
AndroidDebugBridge.addDeviceChangeListener(this);
loadImages();
@@ -339,15 +341,15 @@ public class DeviceChooserDialog extends Dialog implements IDeviceChangeListener
composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
mUseDeviceForFutureLaunchesCheckbox = new Button(composite, SWT.CHECK);
- mUseDeviceForFutureLaunchesCheckbox.setSelection(sUseDeviceForFutureLaunchesValue);
- mResponse.setUseDeviceForFutureLaunches(sUseDeviceForFutureLaunchesValue);
+ mUseDeviceForFutureLaunchesCheckbox.setSelection(mUseDeviceForFutureLaunches);
+ mResponse.setUseDeviceForFutureLaunches(mUseDeviceForFutureLaunches);
mUseDeviceForFutureLaunchesCheckbox.setText("Use same device for future launches");
mUseDeviceForFutureLaunchesCheckbox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- sUseDeviceForFutureLaunchesValue =
+ mUseDeviceForFutureLaunches =
mUseDeviceForFutureLaunchesCheckbox.getSelection();
- mResponse.setUseDeviceForFutureLaunches(sUseDeviceForFutureLaunchesValue);
+ mResponse.setUseDeviceForFutureLaunches(mUseDeviceForFutureLaunches);
}
});
mUseDeviceForFutureLaunchesCheckbox.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/EmulatorConfigTab.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/EmulatorConfigTab.java
index eee154233..248cb7a2c 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/EmulatorConfigTab.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/EmulatorConfigTab.java
@@ -84,26 +84,17 @@ public class EmulatorConfigTab extends AbstractLaunchConfigurationTab {
private Button mAutoTargetButton;
private Button mManualTargetButton;
-
private AvdSelector mPreferredAvdSelector;
-
private Combo mSpeedCombo;
-
private Combo mDelayCombo;
-
private Group mEmulatorOptionsGroup;
-
private Text mEmulatorCLOptions;
-
private Button mWipeDataButton;
-
private Button mNoBootAnimButton;
-
private Label mPreferredAvdLabel;
-
private IAndroidTarget mProjectTarget;
private AndroidVersion mProjectMinApiVersion;
-
+ private Button mFutureLaunchesOnSameDevice;
private boolean mSupportMultiDeviceLaunch;
private Button mAllDevicesTargetButton;
private Combo mDeviceTypeCombo;
@@ -256,6 +247,10 @@ public class EmulatorConfigTab extends AbstractLaunchConfigurationTab {
mPreferredAvdSelector.setSelectionListener(listener);
mDeviceTypeCombo.addSelectionListener(listener);
+ mFutureLaunchesOnSameDevice = new Button(targetModeGroup, SWT.CHECK);
+ mFutureLaunchesOnSameDevice.setText("Use same device for future launches");
+ mFutureLaunchesOnSameDevice.addSelectionListener(listener);
+
// emulator size
mEmulatorOptionsGroup = new Group(topComp, SWT.NONE);
mEmulatorOptionsGroup.setText("Emulator launch parameters:");
@@ -280,13 +275,7 @@ public class EmulatorConfigTab extends AbstractLaunchConfigurationTab {
for (String[] speed : NETWORK_SPEEDS) {
mSpeedCombo.add(speed[0]);
}
- mSpeedCombo.addSelectionListener(new SelectionAdapter() {
- // called when selection changes
- @Override
- public void widgetSelected(SelectionEvent e) {
- updateLaunchConfigurationDialog();
- }
- });
+ mSpeedCombo.addSelectionListener(listener);
mSpeedCombo.pack();
new Label(mEmulatorOptionsGroup, SWT.NONE).setText("Network Latency:");
@@ -296,13 +285,7 @@ public class EmulatorConfigTab extends AbstractLaunchConfigurationTab {
for (String[] delay : NETWORK_LATENCIES) {
mDelayCombo.add(delay[0]);
}
- mDelayCombo.addSelectionListener(new SelectionAdapter() {
- // called when selection changes
- @Override
- public void widgetSelected(SelectionEvent e) {
- updateLaunchConfigurationDialog();
- }
- });
+ mDelayCombo.addSelectionListener(listener);
mDelayCombo.pack();
// wipe data option
@@ -312,12 +295,7 @@ public class EmulatorConfigTab extends AbstractLaunchConfigurationTab {
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
mWipeDataButton.setLayoutData(gd);
- mWipeDataButton.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- updateLaunchConfigurationDialog();
- }
- });
+ mWipeDataButton.addSelectionListener(listener);
// no boot anim option
mNoBootAnimButton = new Button(mEmulatorOptionsGroup, SWT.CHECK);
@@ -326,12 +304,7 @@ public class EmulatorConfigTab extends AbstractLaunchConfigurationTab {
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
mNoBootAnimButton.setLayoutData(gd);
- mNoBootAnimButton.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- updateLaunchConfigurationDialog();
- }
- });
+ mNoBootAnimButton.addSelectionListener(listener);
// custom command line option for emulator
l = new Label(mEmulatorOptionsGroup, SWT.NONE);
@@ -427,6 +400,15 @@ public class EmulatorConfigTab extends AbstractLaunchConfigurationTab {
targetModeChanged();
+ boolean reuseLastUsedDevice;
+ try {
+ reuseLastUsedDevice = configuration.getAttribute(
+ LaunchConfigDelegate.ATTR_REUSE_LAST_USED_DEVICE, false);
+ } catch (CoreException ex) {
+ reuseLastUsedDevice = false;
+ }
+ mFutureLaunchesOnSameDevice.setSelection(reuseLastUsedDevice);
+
mDeviceTypeCombo.setEnabled(multipleDevices);
if (multipleDevices) {
int index = 0;
@@ -552,6 +534,8 @@ public class EmulatorConfigTab extends AbstractLaunchConfigurationTab {
public void performApply(ILaunchConfigurationWorkingCopy configuration) {
configuration.setAttribute(LaunchConfigDelegate.ATTR_TARGET_MODE,
getCurrentTargetMode().toString());
+ configuration.setAttribute(LaunchConfigDelegate.ATTR_REUSE_LAST_USED_DEVICE,
+ mFutureLaunchesOnSameDevice.getSelection());
AvdInfo avd = mPreferredAvdSelector.getSelected();
if (avd != null) {
configuration.setAttribute(LaunchConfigDelegate.ATTR_AVD_NAME, avd.getName());
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/LaunchConfigDelegate.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/LaunchConfigDelegate.java
index c9e7e6a9a..86fc2ffae 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/LaunchConfigDelegate.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/LaunchConfigDelegate.java
@@ -51,6 +51,14 @@ public class LaunchConfigDelegate extends LaunchConfigurationDelegate {
public static final String ATTR_TARGET_MODE = AdtPlugin.PLUGIN_ID + ".target"; //$NON-NLS-1$
public static final TargetMode DEFAULT_TARGET_MODE = TargetMode.AUTO;
+ /** Flag indicating whether the last used device should be used for future launches. */
+ public static final String ATTR_REUSE_LAST_USED_DEVICE =
+ AdtPlugin.PLUGIN_ID + ".reuse.last.used.device"; //$NON-NLS-1$
+
+ /** Device on which the last launch happened. */
+ public static final String ATTR_LAST_USED_DEVICE =
+ AdtPlugin.PLUGIN_ID + ".last.used.device"; //$NON-NLS-1$
+
/**
* Launch action:
* <ul>
diff --git a/eclipse/plugins/com.android.ide.eclipse.ndk/src/com/android/ide/eclipse/ndk/internal/launch/NdkGdbLaunchDelegate.java b/eclipse/plugins/com.android.ide.eclipse.ndk/src/com/android/ide/eclipse/ndk/internal/launch/NdkGdbLaunchDelegate.java
index 651121ac3..0b124f249 100644
--- a/eclipse/plugins/com.android.ide.eclipse.ndk/src/com/android/ide/eclipse/ndk/internal/launch/NdkGdbLaunchDelegate.java
+++ b/eclipse/plugins/com.android.ide.eclipse.ndk/src/com/android/ide/eclipse/ndk/internal/launch/NdkGdbLaunchDelegate.java
@@ -16,6 +16,8 @@
package com.android.ide.eclipse.ndk.internal.launch;
+import com.android.annotations.NonNull;
+import com.android.annotations.Nullable;
import com.android.ddmlib.AdbCommandRejectedException;
import com.android.ddmlib.AndroidDebugBridge;
import com.android.ddmlib.Client;
@@ -30,7 +32,7 @@ import com.android.ide.common.xml.ManifestData;
import com.android.ide.common.xml.ManifestData.Activity;
import com.android.ide.eclipse.adt.AdtPlugin;
import com.android.ide.eclipse.adt.internal.editors.manifest.ManifestInfo;
-import com.android.ide.eclipse.adt.internal.launch.DeviceChoiceCache;
+import com.android.ide.eclipse.adt.internal.launch.AndroidLaunchController;
import com.android.ide.eclipse.adt.internal.launch.DeviceChooserDialog;
import com.android.ide.eclipse.adt.internal.launch.DeviceChooserDialog.DeviceChooserResponse;
import com.android.ide.eclipse.adt.internal.launch.LaunchConfigDelegate;
@@ -93,7 +95,7 @@ public class NdkGdbLaunchDelegate extends GdbLaunchDelegate {
}
}
- public boolean doLaunch(ILaunchConfiguration config, String mode, ILaunch launch,
+ public boolean doLaunch(final ILaunchConfiguration config, String mode, ILaunch launch,
IProgressMonitor monitor) throws CoreException {
IProject project = null;
ICProject cProject = CDebugUtils.getCProject(config);
@@ -151,9 +153,7 @@ public class NdkGdbLaunchDelegate extends GdbLaunchDelegate {
IDevice[] devices = AndroidDebugBridge.getBridge().getDevices();
if (devices.length == 1) {
device = devices[0];
- } else if (DeviceChoiceCache.get(configName) != null) {
- device = DeviceChoiceCache.get(configName);
- } else {
+ } else if ((device = getLastUsedDevice(config, devices)) == null) {
final IAndroidTarget projectTarget = Sdk.getCurrent().getTarget(project);
final DeviceChooserResponse response = new DeviceChooserResponse();
final boolean continueLaunch[] = new boolean[] { false };
@@ -164,9 +164,10 @@ public class NdkGdbLaunchDelegate extends GdbLaunchDelegate {
AdtPlugin.getDisplay().getActiveShell(),
response,
manifestData.getPackage(),
- projectTarget, minSdkVersion);
+ projectTarget, minSdkVersion, false /*** FIXME! **/);
if (dialog.open() == Dialog.OK) {
- DeviceChoiceCache.put(configName, response);
+ AndroidLaunchController.updateLaunchConfigWithLastUsedDevice(config,
+ response);
continueLaunch[0] = true;
}
};
@@ -341,14 +342,32 @@ public class NdkGdbLaunchDelegate extends GdbLaunchDelegate {
}
// update launch attributes based on device
- config = performVariableSubstitutions(config, project, compatAbi, monitor);
+ ILaunchConfiguration config2 = performVariableSubstitutions(config, project, compatAbi,
+ monitor);
// launch gdb
monitor.setTaskName(Messages.NdkGdbLaunchDelegate_Action_LaunchHostGdb);
- super.launch(config, mode, launch, monitor);
+ super.launch(config2, mode, launch, monitor);
return true;
}
+ @Nullable
+ private IDevice getLastUsedDevice(ILaunchConfiguration config, @NonNull IDevice[] devices) {
+ try {
+ boolean reuse = config.getAttribute(LaunchConfigDelegate.ATTR_REUSE_LAST_USED_DEVICE,
+ false);
+ if (!reuse) {
+ return null;
+ }
+
+ String serial = config.getAttribute(LaunchConfigDelegate.ATTR_LAST_USED_DEVICE,
+ (String)null);
+ return AndroidLaunchController.getDeviceIfOnline(serial, devices);
+ } catch (CoreException e) {
+ return null;
+ }
+ }
+
private void pull(IDevice device, String remote, IPath solibFolder) throws
SyncException, IOException, AdbCommandRejectedException, TimeoutException {
String remoteFileName = new Path(remote).toFile().getName();