1 /*
2  * Copyright (C) 2007 The Android Open Source Project
3  *
4  * Licensed under the Eclipse Public License, Version 1.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.eclipse.org/org/documents/epl-v10.php
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.ide.eclipse.adt.internal.launch;
18 
19 import com.android.ddmuilib.ImageLoader;
20 import com.android.ide.eclipse.adt.AdtPlugin;
21 import com.android.ide.eclipse.adt.internal.editors.manifest.ManifestInfo;
22 import com.android.ide.eclipse.adt.internal.launch.AndroidLaunchConfiguration.TargetMode;
23 import com.android.ide.eclipse.adt.internal.launch.AvdCompatibility.Compatibility;
24 import com.android.ide.eclipse.adt.internal.preferences.AdtPrefs;
25 import com.android.ide.eclipse.adt.internal.project.BaseProjectHelper;
26 import com.android.ide.eclipse.adt.internal.sdk.AdtConsoleSdkLog;
27 import com.android.ide.eclipse.adt.internal.sdk.Sdk;
28 import com.android.prefs.AndroidLocation.AndroidLocationException;
29 import com.android.sdklib.AndroidVersion;
30 import com.android.sdklib.IAndroidTarget;
31 import com.android.sdklib.internal.avd.AvdInfo;
32 import com.android.sdklib.internal.avd.AvdManager;
33 import com.android.sdkuilib.internal.widgets.AvdSelector;
34 import com.android.sdkuilib.internal.widgets.AvdSelector.DisplayMode;
35 import com.android.sdkuilib.internal.widgets.AvdSelector.IAvdFilter;
36 import com.android.utils.NullLogger;
37 
38 import org.eclipse.core.resources.IProject;
39 import org.eclipse.core.runtime.CoreException;
40 import org.eclipse.debug.core.ILaunchConfiguration;
41 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
42 import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
43 import org.eclipse.jdt.core.IJavaProject;
44 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
45 import org.eclipse.jface.preference.IPreferenceStore;
46 import org.eclipse.swt.SWT;
47 import org.eclipse.swt.events.ModifyEvent;
48 import org.eclipse.swt.events.ModifyListener;
49 import org.eclipse.swt.events.SelectionAdapter;
50 import org.eclipse.swt.events.SelectionEvent;
51 import org.eclipse.swt.events.SelectionListener;
52 import org.eclipse.swt.graphics.Font;
53 import org.eclipse.swt.graphics.Image;
54 import org.eclipse.swt.layout.GridData;
55 import org.eclipse.swt.layout.GridLayout;
56 import org.eclipse.swt.widgets.Button;
57 import org.eclipse.swt.widgets.Combo;
58 import org.eclipse.swt.widgets.Composite;
59 import org.eclipse.swt.widgets.Group;
60 import org.eclipse.swt.widgets.Label;
61 import org.eclipse.swt.widgets.Text;
62 
63 /**
64  * Launch configuration tab to control the parameters of the Emulator
65  */
66 public class EmulatorConfigTab extends AbstractLaunchConfigurationTab {
67 
68     private final static String[][] NETWORK_SPEEDS = new String[][] {
69         { "Full", "full" }, //$NON-NLS-2$
70         { "GSM", "gsm" }, //$NON-NLS-2$
71         { "HSCSD", "hscsd" }, //$NON-NLS-2$
72         { "GPRS", "gprs" }, //$NON-NLS-2$
73         { "EDGE", "edge" }, //$NON-NLS-2$
74         { "UMTS", "umts" }, //$NON-NLS-2$
75         { "HSPDA", "hsdpa" }, //$NON-NLS-2$
76     };
77 
78     private final static String[][] NETWORK_LATENCIES = new String[][] {
79         { "None", "none" }, //$NON-NLS-2$
80         { "GPRS", "gprs" }, //$NON-NLS-2$
81         { "EDGE", "edge" }, //$NON-NLS-2$
82         { "UMTS", "umts" }, //$NON-NLS-2$
83     };
84 
85     private Button mAutoTargetButton;
86     private Button mManualTargetButton;
87     private AvdSelector mPreferredAvdSelector;
88     private Combo mSpeedCombo;
89     private Combo mDelayCombo;
90     private Group mEmulatorOptionsGroup;
91     private Text mEmulatorCLOptions;
92     private Button mWipeDataButton;
93     private Button mNoBootAnimButton;
94     private Label mPreferredAvdLabel;
95     private IAndroidTarget mProjectTarget;
96     private AndroidVersion mProjectMinApiVersion;
97     private Button mFutureLaunchesOnSameDevice;
98     private boolean mSupportMultiDeviceLaunch;
99     private Button mAllDevicesTargetButton;
100     private Combo mDeviceTypeCombo;
101 
102     private static final String DEVICES_AND_EMULATORS = "Active devices and AVD's";
103     private static final String EMULATORS_ONLY = "Active AVD's";
104     private static final String DEVICES_ONLY = "Active devices";
105 
106     /**
107      * Returns the emulator ready speed option value.
108      * @param value The index of the combo selection.
109      */
getSpeed(int value)110     public static String getSpeed(int value) {
111         try {
112             return NETWORK_SPEEDS[value][1];
113         } catch (ArrayIndexOutOfBoundsException e) {
114             return NETWORK_SPEEDS[LaunchConfigDelegate.DEFAULT_SPEED][1];
115         }
116     }
117 
118     /**
119      * Returns the emulator ready network latency value.
120      * @param value The index of the combo selection.
121      */
getDelay(int value)122     public static String getDelay(int value) {
123         try {
124             return NETWORK_LATENCIES[value][1];
125         } catch (ArrayIndexOutOfBoundsException e) {
126             return NETWORK_LATENCIES[LaunchConfigDelegate.DEFAULT_DELAY][1];
127         }
128     }
129 
130     /**
131      *
132      */
EmulatorConfigTab(boolean supportMultiDeviceLaunch)133     public EmulatorConfigTab(boolean supportMultiDeviceLaunch) {
134         mSupportMultiDeviceLaunch = supportMultiDeviceLaunch;
135     }
136 
137     /**
138      * @wbp.parser.entryPoint
139      */
140     @Override
createControl(Composite parent)141     public void createControl(Composite parent) {
142         Font font = parent.getFont();
143 
144         // Reload the AVDs to make sure we are up to date
145         try {
146             // SDK can be null if the user opens the dialog before ADT finished
147             // initializing the SDK itself. In this case just don't reload anything
148             // so there's nothing obsolete yet.
149             Sdk sdk = Sdk.getCurrent();
150             if (sdk != null) {
151                 AvdManager avdMan = sdk.getAvdManager();
152                 assert avdMan != null;
153                 avdMan.reloadAvds(NullLogger.getLogger());
154             }
155         } catch (AndroidLocationException e1) {
156             // this happens if the AVD Manager failed to find the folder in which the AVDs are
157             // stored. There isn't much we can do at this point.
158         }
159 
160         Composite topComp = new Composite(parent, SWT.NONE);
161         setControl(topComp);
162         GridLayout topLayout = new GridLayout();
163         topLayout.numColumns = 1;
164         topLayout.verticalSpacing = 0;
165         topComp.setLayout(topLayout);
166         topComp.setFont(font);
167 
168         GridData gd;
169         GridLayout layout;
170 
171         // radio button for the target mode
172         Group targetModeGroup = new Group(topComp, SWT.NONE);
173         targetModeGroup.setText("Deployment Target Selection Mode");
174         gd = new GridData(GridData.FILL_HORIZONTAL);
175         targetModeGroup.setLayoutData(gd);
176         layout = new GridLayout();
177         layout.numColumns = 1;
178         targetModeGroup.setLayout(layout);
179         targetModeGroup.setFont(font);
180 
181         mManualTargetButton = new Button(targetModeGroup, SWT.RADIO);
182         mManualTargetButton.setText("Always prompt to pick device");
183 
184         mAllDevicesTargetButton = new Button(targetModeGroup, SWT.RADIO);
185         mAllDevicesTargetButton.setText("Launch on all compatible devices/AVD's");
186         mAllDevicesTargetButton.setEnabled(mSupportMultiDeviceLaunch);
187 
188         Composite deviceTypeOffsetComp = new Composite(targetModeGroup, SWT.NONE);
189         deviceTypeOffsetComp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
190         layout = new GridLayout(1, false);
191         layout.marginRight = layout.marginHeight = 0;
192         layout.marginLeft = 30;
193         deviceTypeOffsetComp.setLayout(layout);
194 
195         mDeviceTypeCombo = new Combo(deviceTypeOffsetComp, SWT.READ_ONLY);
196         mDeviceTypeCombo.setItems(new String[] {
197                 DEVICES_AND_EMULATORS,
198                 EMULATORS_ONLY,
199                 DEVICES_ONLY,
200         });
201         mDeviceTypeCombo.select(0);
202         mDeviceTypeCombo.setEnabled(false);
203 
204         // add the radio button
205         mAutoTargetButton = new Button(targetModeGroup, SWT.RADIO);
206         mAutoTargetButton.setText("Automatically pick compatible device: "
207                 + "Always uses preferred AVD if set below, "
208                 + "launches on compatible device/AVD otherwise.");
209         mAutoTargetButton.setSelection(true);
210 
211         SelectionListener targetModeChangeListener = new SelectionAdapter() {
212             @Override
213             public void widgetSelected(SelectionEvent e) {
214                 targetModeChanged();
215             }
216         };
217 
218         mAutoTargetButton.addSelectionListener(targetModeChangeListener);
219         mAllDevicesTargetButton.addSelectionListener(targetModeChangeListener);
220         mManualTargetButton.addSelectionListener(targetModeChangeListener);
221 
222         Composite avdOffsetComp = new Composite(targetModeGroup, SWT.NONE);
223         avdOffsetComp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
224         layout = new GridLayout(1, false);
225         layout.marginRight = layout.marginHeight = 0;
226         layout.marginLeft = 30;
227         avdOffsetComp.setLayout(layout);
228 
229         mPreferredAvdLabel = new Label(avdOffsetComp, SWT.NONE);
230         mPreferredAvdLabel.setText("Select a preferred Android Virtual Device for deployment:");
231 
232         // create the selector with no manager, we'll reset the manager every time this is
233         // displayed to ensure we have the latest one (dialog is reused but SDK could have
234         // been changed in between.
235         mPreferredAvdSelector = new AvdSelector(avdOffsetComp,
236                 Sdk.getCurrent().getSdkOsLocation(),
237                 null /* avd manager */,
238                 DisplayMode.SIMPLE_CHECK,
239                 new AdtConsoleSdkLog());
240         mPreferredAvdSelector.setTableHeightHint(100);
241         SelectionListener listener = new SelectionAdapter() {
242             @Override
243             public void widgetSelected(SelectionEvent e) {
244                 updateLaunchConfigurationDialog();
245             }
246         };
247         mPreferredAvdSelector.setSelectionListener(listener);
248         mDeviceTypeCombo.addSelectionListener(listener);
249 
250         mFutureLaunchesOnSameDevice = new Button(targetModeGroup, SWT.CHECK);
251         mFutureLaunchesOnSameDevice.setText("Use same device for future launches");
252         mFutureLaunchesOnSameDevice.addSelectionListener(listener);
253 
254         // emulator size
255         mEmulatorOptionsGroup = new Group(topComp, SWT.NONE);
256         mEmulatorOptionsGroup.setText("Emulator launch parameters:");
257         mEmulatorOptionsGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
258         layout = new GridLayout();
259         layout.numColumns = 2;
260         mEmulatorOptionsGroup.setLayout(layout);
261         mEmulatorOptionsGroup.setFont(font);
262 
263         // Explanation
264         Label l = new Label(mEmulatorOptionsGroup, SWT.NONE);
265         l.setText("If no compatible and active devices or AVD's are found, then an AVD "
266                  + "might be launched. Provide options for the AVD launch below.");
267         gd = new GridData();
268         gd.horizontalSpan = 2;
269         l.setLayoutData(gd);
270 
271         // network options
272         new Label(mEmulatorOptionsGroup, SWT.NONE).setText("Network Speed:");
273 
274         mSpeedCombo = new Combo(mEmulatorOptionsGroup, SWT.READ_ONLY);
275         for (String[] speed : NETWORK_SPEEDS) {
276             mSpeedCombo.add(speed[0]);
277         }
278         mSpeedCombo.addSelectionListener(listener);
279         mSpeedCombo.pack();
280 
281         new Label(mEmulatorOptionsGroup, SWT.NONE).setText("Network Latency:");
282 
283         mDelayCombo = new Combo(mEmulatorOptionsGroup, SWT.READ_ONLY);
284 
285         for (String[] delay : NETWORK_LATENCIES) {
286             mDelayCombo.add(delay[0]);
287         }
288         mDelayCombo.addSelectionListener(listener);
289         mDelayCombo.pack();
290 
291         // wipe data option
292         mWipeDataButton = new Button(mEmulatorOptionsGroup, SWT.CHECK);
293         mWipeDataButton.setText("Wipe User Data");
294         mWipeDataButton.setToolTipText("Check this if you want to wipe your user data each time you start the emulator. You will be prompted for confirmation when the emulator starts.");
295         gd = new GridData(GridData.FILL_HORIZONTAL);
296         gd.horizontalSpan = 2;
297         mWipeDataButton.setLayoutData(gd);
298         mWipeDataButton.addSelectionListener(listener);
299 
300         // no boot anim option
301         mNoBootAnimButton = new Button(mEmulatorOptionsGroup, SWT.CHECK);
302         mNoBootAnimButton.setText("Disable Boot Animation");
303         mNoBootAnimButton.setToolTipText("Check this if you want to disable the boot animation. This can help the emulator start faster on slow machines.");
304         gd = new GridData(GridData.FILL_HORIZONTAL);
305         gd.horizontalSpan = 2;
306         mNoBootAnimButton.setLayoutData(gd);
307         mNoBootAnimButton.addSelectionListener(listener);
308 
309         // custom command line option for emulator
310         l = new Label(mEmulatorOptionsGroup, SWT.NONE);
311         l.setText("Additional Emulator Command Line Options");
312         gd = new GridData(GridData.FILL_HORIZONTAL);
313         gd.horizontalSpan = 2;
314         l.setLayoutData(gd);
315 
316         mEmulatorCLOptions = new Text(mEmulatorOptionsGroup, SWT.BORDER);
317         gd = new GridData(GridData.FILL_HORIZONTAL);
318         gd.horizontalSpan = 2;
319         mEmulatorCLOptions.setLayoutData(gd);
320         mEmulatorCLOptions.addModifyListener(new ModifyListener() {
321             @Override
322             public void modifyText(ModifyEvent e) {
323                 updateLaunchConfigurationDialog();
324             }
325         });
326     }
327 
targetModeChanged()328     private void targetModeChanged() {
329         updateLaunchConfigurationDialog();
330 
331         boolean auto = mAutoTargetButton.getSelection();
332         mPreferredAvdSelector.setEnabled(auto);
333         mPreferredAvdLabel.setEnabled(auto);
334 
335         boolean all = mAllDevicesTargetButton.getSelection();
336         mDeviceTypeCombo.setEnabled(all);
337     }
338 
339     /* (non-Javadoc)
340      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName()
341      */
342     @Override
getName()343     public String getName() {
344         return "Target";
345     }
346 
347     @Override
getImage()348     public Image getImage() {
349         return ImageLoader.getDdmUiLibLoader().loadImage("emulator.png", null); //$NON-NLS-1$
350     }
351 
updateAvdList(AvdManager avdManager)352     private void updateAvdList(AvdManager avdManager) {
353         if (avdManager == null) {
354             avdManager = Sdk.getCurrent().getAvdManager();
355         }
356 
357         mPreferredAvdSelector.setManager(avdManager);
358         mPreferredAvdSelector.refresh(false);
359 
360         mPreferredAvdSelector.setFilter(new IAvdFilter() {
361             @Override
362             public void prepare() {
363             }
364 
365             @Override
366             public void cleanup() {
367             }
368 
369             @Override
370             public boolean accept(AvdInfo avd) {
371                 AvdCompatibility.Compatibility c =
372                         AvdCompatibility.canRun(avd, mProjectTarget, mProjectMinApiVersion);
373                 return (c == Compatibility.NO) ? false : true;
374             }
375         });
376     }
377 
378     /* (non-Javadoc)
379      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
380      */
381     @Override
initializeFrom(ILaunchConfiguration configuration)382     public void initializeFrom(ILaunchConfiguration configuration) {
383         AvdManager avdManager = Sdk.getCurrent().getAvdManager();
384 
385         TargetMode mode = AndroidLaunchConfiguration.parseTargetMode(configuration,
386                 LaunchConfigDelegate.DEFAULT_TARGET_MODE);
387 
388         boolean multipleDevices = mode.isMultiDevice();
389         if (multipleDevices && !mSupportMultiDeviceLaunch) {
390             // The launch config says to run on multiple devices, but this launch type does not
391             // suppport multiple devices. In such a case, switch back to default mode.
392             // This could happen if a launch config used for Run is then used for Debug.
393             multipleDevices = false;
394             mode = LaunchConfigDelegate.DEFAULT_TARGET_MODE;
395         }
396 
397         mAutoTargetButton.setSelection(mode == TargetMode.AUTO);
398         mManualTargetButton.setSelection(mode == TargetMode.MANUAL);
399         mAllDevicesTargetButton.setSelection(multipleDevices);
400 
401         targetModeChanged();
402 
403         boolean reuseLastUsedDevice;
404         try {
405             reuseLastUsedDevice = configuration.getAttribute(
406                     LaunchConfigDelegate.ATTR_REUSE_LAST_USED_DEVICE, false);
407         } catch (CoreException ex) {
408             reuseLastUsedDevice = false;
409         }
410         mFutureLaunchesOnSameDevice.setSelection(reuseLastUsedDevice);
411 
412         mDeviceTypeCombo.setEnabled(multipleDevices);
413         if (multipleDevices) {
414             int index = 0;
415             if (mode == TargetMode.ALL_EMULATORS) {
416                 index = 1;
417             } else if (mode == TargetMode.ALL_DEVICES) {
418                 index = 2;
419             }
420             mDeviceTypeCombo.select(index);
421         }
422 
423         // look for the project name to get its target.
424         String stringValue = "";
425         try {
426             stringValue = configuration.getAttribute(
427                     IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, stringValue);
428         } catch (CoreException ce) {
429             // let's not do anything here, we'll use the default value
430         }
431 
432         IProject project = null;
433 
434         // get the list of existing Android projects from the workspace.
435         IJavaProject[] projects = BaseProjectHelper.getAndroidProjects(null /*filter*/);
436         if (projects != null) {
437             // look for the project whose name we read from the configuration.
438             for (IJavaProject p : projects) {
439                 if (p.getElementName().equals(stringValue)) {
440                     project = p.getProject();
441                     break;
442                 }
443             }
444         }
445 
446         // update the AVD list
447         if (project != null) {
448             mProjectTarget = Sdk.getCurrent().getTarget(project);
449 
450             ManifestInfo mi = ManifestInfo.get(project);
451             final int minApiLevel = mi.getMinSdkVersion();
452             final String minApiCodeName = mi.getMinSdkCodeName();
453             mProjectMinApiVersion = new AndroidVersion(minApiLevel, minApiCodeName);
454         }
455 
456         updateAvdList(avdManager);
457 
458         stringValue = "";
459         try {
460             stringValue = configuration.getAttribute(LaunchConfigDelegate.ATTR_AVD_NAME,
461                     stringValue);
462         } catch (CoreException e) {
463             // let's not do anything here, we'll use the default value
464         }
465 
466         if (stringValue != null && stringValue.length() > 0 && avdManager != null) {
467             AvdInfo targetAvd = avdManager.getAvd(stringValue, true /*validAvdOnly*/);
468             mPreferredAvdSelector.setSelection(targetAvd);
469         } else {
470             mPreferredAvdSelector.setSelection(null);
471         }
472 
473         boolean value = LaunchConfigDelegate.DEFAULT_WIPE_DATA;
474         try {
475             value = configuration.getAttribute(LaunchConfigDelegate.ATTR_WIPE_DATA, value);
476         } catch (CoreException e) {
477             // let's not do anything here, we'll use the default value
478         }
479         mWipeDataButton.setSelection(value);
480 
481         value = LaunchConfigDelegate.DEFAULT_NO_BOOT_ANIM;
482         try {
483             value = configuration.getAttribute(LaunchConfigDelegate.ATTR_NO_BOOT_ANIM, value);
484         } catch (CoreException e) {
485             // let's not do anything here, we'll use the default value
486         }
487         mNoBootAnimButton.setSelection(value);
488 
489         int index = -1;
490 
491         index = LaunchConfigDelegate.DEFAULT_SPEED;
492         try {
493             index = configuration.getAttribute(LaunchConfigDelegate.ATTR_SPEED,
494                     index);
495         } catch (CoreException e) {
496             // let's not do anything here, we'll use the default value
497         }
498         if (index == -1) {
499             mSpeedCombo.clearSelection();
500         } else {
501             mSpeedCombo.select(index);
502         }
503 
504         index = LaunchConfigDelegate.DEFAULT_DELAY;
505         try {
506             index = configuration.getAttribute(LaunchConfigDelegate.ATTR_DELAY,
507                     index);
508         } catch (CoreException e) {
509             // let's not do anything here, we'll put a proper value in
510             // performApply anyway
511         }
512         if (index == -1) {
513             mDelayCombo.clearSelection();
514         } else {
515             mDelayCombo.select(index);
516         }
517 
518         String commandLine = null;
519         try {
520             commandLine = configuration.getAttribute(
521                     LaunchConfigDelegate.ATTR_COMMANDLINE, ""); //$NON-NLS-1$
522         } catch (CoreException e) {
523             // let's not do anything here, we'll use the default value
524         }
525         if (commandLine != null) {
526             mEmulatorCLOptions.setText(commandLine);
527         }
528     }
529 
530     /* (non-Javadoc)
531      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
532      */
533     @Override
performApply(ILaunchConfigurationWorkingCopy configuration)534     public void performApply(ILaunchConfigurationWorkingCopy configuration) {
535         configuration.setAttribute(LaunchConfigDelegate.ATTR_TARGET_MODE,
536                 getCurrentTargetMode().toString());
537         configuration.setAttribute(LaunchConfigDelegate.ATTR_REUSE_LAST_USED_DEVICE,
538                 mFutureLaunchesOnSameDevice.getSelection());
539         AvdInfo avd = mPreferredAvdSelector.getSelected();
540         if (avd != null) {
541             configuration.setAttribute(LaunchConfigDelegate.ATTR_AVD_NAME, avd.getName());
542         } else {
543             configuration.setAttribute(LaunchConfigDelegate.ATTR_AVD_NAME, (String)null);
544         }
545         configuration.setAttribute(LaunchConfigDelegate.ATTR_SPEED,
546                 mSpeedCombo.getSelectionIndex());
547         configuration.setAttribute(LaunchConfigDelegate.ATTR_DELAY,
548                 mDelayCombo.getSelectionIndex());
549         configuration.setAttribute(LaunchConfigDelegate.ATTR_COMMANDLINE,
550                 mEmulatorCLOptions.getText());
551         configuration.setAttribute(LaunchConfigDelegate.ATTR_WIPE_DATA,
552                 mWipeDataButton.getSelection());
553         configuration.setAttribute(LaunchConfigDelegate.ATTR_NO_BOOT_ANIM,
554                 mNoBootAnimButton.getSelection());
555    }
556 
getCurrentTargetMode()557     private TargetMode getCurrentTargetMode() {
558         if (mAutoTargetButton.getSelection()) {
559             return TargetMode.AUTO;
560         } else if (mManualTargetButton.getSelection()) {
561             return TargetMode.MANUAL;
562         } else {
563             String selection = mDeviceTypeCombo.getText();
564             if (DEVICES_AND_EMULATORS.equals(selection)) {
565                 return TargetMode.ALL_DEVICES_AND_EMULATORS;
566             } else if (DEVICES_ONLY.equals(selection)) {
567                 return TargetMode.ALL_DEVICES;
568             } else if (EMULATORS_ONLY.equals(selection)) {
569                 return TargetMode.ALL_EMULATORS;
570             }
571         }
572 
573         return TargetMode.AUTO;
574     }
575 
576     /* (non-Javadoc)
577      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
578      */
579     @Override
setDefaults(ILaunchConfigurationWorkingCopy configuration)580     public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
581         configuration.setAttribute(LaunchConfigDelegate.ATTR_TARGET_MODE,
582                 LaunchConfigDelegate.DEFAULT_TARGET_MODE.toString());
583         configuration.setAttribute(LaunchConfigDelegate.ATTR_SPEED,
584                 LaunchConfigDelegate.DEFAULT_SPEED);
585         configuration.setAttribute(LaunchConfigDelegate.ATTR_DELAY,
586                 LaunchConfigDelegate.DEFAULT_DELAY);
587         configuration.setAttribute(LaunchConfigDelegate.ATTR_WIPE_DATA,
588                 LaunchConfigDelegate.DEFAULT_WIPE_DATA);
589         configuration.setAttribute(LaunchConfigDelegate.ATTR_NO_BOOT_ANIM,
590                 LaunchConfigDelegate.DEFAULT_NO_BOOT_ANIM);
591 
592         IPreferenceStore store = AdtPlugin.getDefault().getPreferenceStore();
593         String emuOptions = store.getString(AdtPrefs.PREFS_EMU_OPTIONS);
594         configuration.setAttribute(LaunchConfigDelegate.ATTR_COMMANDLINE, emuOptions);
595    }
596 }
597