diff options
author | Siva Velusamy <vsiva@google.com> | 2012-03-21 10:28:08 -0700 |
---|---|---|
committer | Siva Velusamy <vsiva@google.com> | 2012-03-26 15:45:14 -0700 |
commit | 805a03988e828ff574ab02e9b7d812b07b493156 (patch) | |
tree | abc4ec8421e51f27315f1b89c64b019b599cd040 | |
parent | 1091d6a7cb67cf4efbda20402f4db4aa477fc452 (diff) | |
download | sdk-805a03988e828ff574ab02e9b7d812b07b493156.zip sdk-805a03988e828ff574ab02e9b7d812b07b493156.tar.gz sdk-805a03988e828ff574ab02e9b7d812b07b493156.tar.bz2 |
ADT launch: remove unnecessary creation of a new thread
Always call continueLaunch() from a non UI thread. Currently, in
one particular scenario, it is called from the UI thread which
means that it has to do work inside a new thread.
Change-Id: I40cafeb2bb047e1c6575ad5a626830e02d8d2e46
-rw-r--r-- | eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/AndroidLaunchController.java | 73 |
1 files changed, 35 insertions, 38 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 eb66cce..d7d87cb 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 @@ -81,6 +81,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.concurrent.atomic.AtomicBoolean; /** * Controls the launch of Android application either on a device or on the @@ -572,7 +573,8 @@ public final class AndroidLaunchController implements IDebugBridgeChangeListener // bring up the device chooser. final IAndroidTarget desiredProjectTarget = projectTarget; - AdtPlugin.getDisplay().asyncExec(new Runnable() { + final AtomicBoolean continueLaunch = new AtomicBoolean(false); + AdtPlugin.getDisplay().syncExec(new Runnable() { @Override public void run() { try { @@ -584,8 +586,7 @@ public final class AndroidLaunchController implements IDebugBridgeChangeListener if (dialog.open() == Dialog.OK) { updateLaunchOnSameDeviceState(response, launch.getLaunchConfiguration().getName()); - AndroidLaunchController.this.continueLaunch(response, project, launch, - launchInfo, config); + continueLaunch.set(true); } else { AdtPlugin.printErrorToConsole(project, "Launch canceled!"); stopLaunch(launchInfo); @@ -606,6 +607,10 @@ public final class AndroidLaunchController implements IDebugBridgeChangeListener } } }); + + if (continueLaunch.get()) { + continueLaunch(response, project, launch, launchInfo, config); + } } private IDevice getDeviceUsedForLastLaunch(IDevice[] devices, @@ -671,45 +676,37 @@ public final class AndroidLaunchController implements IDebugBridgeChangeListener * @param launchInfo The {@link DelayedLaunchInfo} * @param config The config needed to start a new emulator. */ - void continueLaunch(final DeviceChooserResponse response, final IProject project, + private void continueLaunch(final DeviceChooserResponse response, final IProject project, final AndroidLaunch launch, final DelayedLaunchInfo launchInfo, final AndroidLaunchConfiguration config) { - - // Since this is called from the UI thread we spawn a new thread - // to finish the launch. - new Thread() { - @Override - public void run() { - if (response.getAvdToLaunch() != null) { - // there was no selected device, we start a new emulator. - synchronized (sListLock) { - AvdInfo info = response.getAvdToLaunch(); - mWaitingForEmulatorLaunches.add(launchInfo); - AdtPlugin.printToConsole(project, String.format( - "Launching a new emulator with Virtual Device '%1$s'", - info.getName())); - boolean status = launchEmulator(config, info); - - if (status == false) { - // launching the emulator failed! - AdtPlugin.displayError("Emulator Launch", - "Couldn't launch the emulator! Make sure the SDK directory is properly setup and the emulator is not missing."); - - // stop the launch and return - mWaitingForEmulatorLaunches.remove(launchInfo); - AdtPlugin.printErrorToConsole(project, "Launch canceled!"); - stopLaunch(launchInfo); - return; - } - - return; - } - } else if (response.getDeviceToUse() != null) { - launchInfo.setDevice(response.getDeviceToUse()); - simpleLaunch(launchInfo, launchInfo.getDevice()); + if (response.getAvdToLaunch() != null) { + // there was no selected device, we start a new emulator. + synchronized (sListLock) { + AvdInfo info = response.getAvdToLaunch(); + mWaitingForEmulatorLaunches.add(launchInfo); + AdtPlugin.printToConsole(project, String.format( + "Launching a new emulator with Virtual Device '%1$s'", + info.getName())); + boolean status = launchEmulator(config, info); + + if (status == false) { + // launching the emulator failed! + AdtPlugin.displayError("Emulator Launch", + "Couldn't launch the emulator! Make sure the SDK directory is properly setup and the emulator is not missing."); + + // stop the launch and return + mWaitingForEmulatorLaunches.remove(launchInfo); + AdtPlugin.printErrorToConsole(project, "Launch canceled!"); + stopLaunch(launchInfo); + return; } + + return; } - }.start(); + } else if (response.getDeviceToUse() != null) { + launchInfo.setDevice(response.getDeviceToUse()); + simpleLaunch(launchInfo, launchInfo.getDevice()); + } } /** |