Merge change 1739 into donut

* changes:
  Fix an NPE in the New Project Wizard when no test project is specified on the second NPW page.
diff --git a/build/sdk.atree b/build/sdk.atree
index 8c26b1e..b34a82a 100644
--- a/build/sdk.atree
+++ b/build/sdk.atree
@@ -27,9 +27,6 @@
 bin/hprof-conv tools/hprof-conv
 bin/mksdcard tools/mksdcard
 
-# other tools
-development/tools/scripts/add-accounts-sdk tools/add-accounts.py
-
 # the uper-jar file that apps link against
 out/target/common/obj/PACKAGING/android_jar_intermediates/android.jar platforms/${PLATFORM_NAME}/android.jar
 
diff --git a/ndk/build/core/build-binary.mk b/ndk/build/core/build-binary.mk
index 6254302..f5ebdcb 100644
--- a/ndk/build/core/build-binary.mk
+++ b/ndk/build/core/build-binary.mk
@@ -120,5 +120,5 @@
 $(foreach src,$(s_sources),   $(call compile-s-source,$(src)))
 $(foreach src,$(cpp_sources), $(call compile-cpp-source,$(src)))
 
-LOCAL_DEPENDENCY_DIRS := $(sort $(LOCAL_DEPENDENCY_DIRS))
-CLEAN_OBJS_DIRS       += $(LOCAL_OBJS_DIR)
+ALL_DEPENDENCY_DIRS += $(sort $(LOCAL_DEPENDENCY_DIRS))
+CLEAN_OBJS_DIRS     += $(LOCAL_OBJS_DIR)
diff --git a/ndk/build/core/build-shared-library.mk b/ndk/build/core/build-shared-library.mk
index f07ed80..7cf9841 100644
--- a/ndk/build/core/build-shared-library.mk
+++ b/ndk/build/core/build-shared-library.mk
@@ -54,19 +54,29 @@
 $(LOCAL_BUILT_MODULE): PRIVATE_LDLIBS  := $(LOCAL_LDLIBS) $(TARGET_LDLIBS)
 
 $(LOCAL_BUILT_MODULE): PRIVATE_NAME := $(notdir $(LOCAL_BUILT_MODULE))
-$(LOCAL_BUILT_MODULE): PRIVATE_DEST := $(NDK_APP_DEST)
-$(LOCAL_BUILT_MODULE): PRIVATE_SRC  := $(LOCAL_BUILT_MODULE)
-$(LOCAL_BUILT_MODULE): PRIVATE_DST  := $(PRIVATE_DEST)/$(PRIVATE_NAME)
 
 $(LOCAL_BUILT_MODULE): $(LOCAL_OBJECTS)
 	@ mkdir -p $(dir $@)
 	@ echo "SharedLibrary  : $(PRIVATE_NAME)"
 	$(hide) $(cmd-build-shared-library)
+
+ALL_SHARED_LIBRARIES += $(LOCAL_BUILT_MODULE)
+
+# Installed module handling
+#
+LOCAL_INSTALLED_MODULE := $(NDK_APP_DEST)/$(notdir $(LOCAL_BUILT_MODULE))
+
+$(LOCAL_INSTALLED_MODULE): PRIVATE_NAME := $(notdir $(LOCAL_BUILT_MODULE))
+$(LOCAL_INSTALLED_MODULE): PRIVATE_SRC  := $(LOCAL_BUILT_MODULE)
+$(LOCAL_INSTALLED_MODULE): PRIVATE_DEST := $(NDK_APP_DEST)
+$(LOCAL_INSTALLED_MODULE): PRIVATE_DST  := $(LOCAL_INSTALLED_MODULE)
+
+$(LOCAL_INSTALLED_MODULE): $(LOCAL_BUILT_MODULE)
 	@ echo "Install        : $(PRIVATE_NAME) => $(PRIVATE_DEST)"
 	$(hide) mkdir -p $(PRIVATE_DEST)
 	$(hide) install -p $(PRIVATE_SRC) $(PRIVATE_DST)
 	$(hide) $(call cmd-strip, $(PRIVATE_DST))
 
-ALL_EXECUTABLES += $(LOCAL_BUILT_MODULE)
+ALL_INSTALLED_MODULES += $(LOCAL_INSTALLED_MODULE)
 
 endif # filter LOCAL_MODULE in NDK_APP_MODULES
diff --git a/ndk/build/core/build-static-library.mk b/ndk/build/core/build-static-library.mk
index d36f004..3bbf75e 100644
--- a/ndk/build/core/build-static-library.mk
+++ b/ndk/build/core/build-static-library.mk
@@ -59,6 +59,6 @@
 	$(hide) rm -rf $@
 	$(hide) $(cmd-build-static-library)
 
-ALL_EXECUTABLES += $(LOCAL_BUILT_MODULE)
+ALL_STATIC_LIBRARIES += $(LOCAL_BUILT_MODULE)
 
 endif # filter LOCAL_MODULE in NDK_APP_MODULES
diff --git a/ndk/build/core/main.mk b/ndk/build/core/main.mk
index a82e77e..a07e3b3 100644
--- a/ndk/build/core/main.mk
+++ b/ndk/build/core/main.mk
@@ -193,9 +193,11 @@
 # These phony targets are used to control various stages of the build
 .PHONY: all \
         host_libraries host_executables \
+        installed_modules \
         executables libraries static_libraries shared_libraries \
         clean clean-config clean-objs-dir \
-        clean-executables clean-libraries
+        clean-executables clean-libraries \
+        clean-installed-modules
 
 # These macros are used in Android.mk to include the corresponding
 # build script that will parse the LOCAL_XXX variable definitions.
@@ -220,7 +222,7 @@
 # generated during the build. It will be updated by build scripts
 # when module definitions are parsed.
 #
-DEPENDENCY_DIRS :=
+ALL_DEPENDENCY_DIRS :=
 
 # this is the list of all generated files that we would need to clean
 ALL_HOST_EXECUTABLES      :=
@@ -228,9 +230,10 @@
 ALL_STATIC_LIBRARIES      :=
 ALL_SHARED_LIBRARIES      :=
 ALL_EXECUTABLES           :=
+ALL_INSTALLED_MODULES     :=
 
 # the first rule
-all: libraries executables
+all: installed_modules host_libraries host_executables
 
 # ====================================================================
 #
@@ -260,10 +263,11 @@
 #
 # ====================================================================
 
-clean: clean-intermediates
+clean: clean-intermediates clean-installed-modules
 
 distclean: clean clean-config
 
+installed_modules: libraries $(ALL_INSTALLED_MODULES)
 host_libraries: $(HOST_STATIC_LIBRARIES)
 host_executables: $(HOST_EXECUTABLES)
 
@@ -274,14 +278,17 @@
 libraries: static_libraries shared_libraries
 
 clean-host-intermediates:
-	$(hide) rm -rf $(NDK_HOST_OUT)/objs $(HOST_EXECUTABLES) $(HOST_STATIC_LIBRARIES)
+	$(hide) rm -rf $(HOST_EXECUTABLES) $(HOST_STATIC_LIBRARIES)
 
 clean-intermediates: clean-host-intermediates
-	$(hide) rm -rf $(NDK_HOST_OUT)/objs $(EXECUTABLES) $(STATIC_LIBRARIES) $(SHARED_LIBRARIES)
+	$(hide) rm -rf $(EXECUTABLES) $(STATIC_LIBRARIES) $(SHARED_LIBRARIES)
+
+clean-installed-modules:
+	$(hide) rm -rf $(ALL_INSTALLED_MODULES)
 
 clean-config:
 	$(hide) rm -f $(CONFIG_MAKE) $(CONFIG_H)
 
 # include dependency information
-DEPENDENCY_DIRS := $(sort $(DEPENDENCY_DIRS))
--include $(wildcard $(DEPENDENCY_DIRS:%=%/*.d))
+ALL_DEPENDENCY_DIRS := $(sort $(ALL_DEPENDENCY_DIRS))
+-include $(wildcard $(ALL_DEPENDENCY_DIRS:%=%/*.d))
diff --git a/ndk/build/toolchains/archive/toolchain/sources.txt b/ndk/build/toolchains/archive/toolchain/sources.txt
index 033881a..c59d51a 100644
--- a/ndk/build/toolchains/archive/toolchain/sources.txt
+++ b/ndk/build/toolchains/archive/toolchain/sources.txt
@@ -1,3 +1,3 @@
-android-toolchain-20090323.tar.bz2
+android-ndk-toolchain-20090323.tar.bz2
 d56abac4df36271ae0c961d21d0847db
-http://android.git.kernel.org/pub/android-toolchain-20090323.tar.bz2
\ No newline at end of file
+http://android.git.kernel.org/pub/android-ndk-toolchain-20090323.tar.bz2
diff --git a/ndk/build/tools/build-toolchain.sh b/ndk/build/tools/build-toolchain.sh
index e1047bd..75de8f9 100755
--- a/ndk/build/tools/build-toolchain.sh
+++ b/ndk/build/tools/build-toolchain.sh
@@ -154,13 +154,6 @@
 ANDROID_GDBSERVER_BUILD=$ANDROID_GDBSERVER_OUT/build
 ANDROID_GDBSERVER_DEST=$ANDROID_SYSROOT/usr/bin
 
-# checks, we need more checks..
-mkdir -p $PACKAGE_OUT
-if [ $? != 0 ] ; then
-    echo "Can't create download/archive directory for toolchain tarballs"
-    exit 2
-fi
-
 # Let's check that we have a working md5sum here
 A_MD5=`echo "A" | md5sum | cut -d' ' -f1`
 if [ "$A_MD5" != "bf072e9119077b4e76437a93986787ef" ] ; then
@@ -182,7 +175,7 @@
     echo $1 | grep -q -e "^\(http\|https\):.*"
     if [ $? = 0 ] ; then
         if [ -n "$WGET" ] ; then
-            $WGET -o $2 $1 
+            $WGET -O $2 $1 
         elif [ -n "$CURL" ] ; then
             $CURL -o $2 $1
         else
@@ -352,7 +345,7 @@
 }
 
 if [ $OPTION_FORCE_DOWNLOAD ] ; then
-    rm -rf $ANDROID_TOOLCHAIN_SRC
+    rm -rf $PACKAGE_OUT $ANDROID_TOOLCHAIN_SRC
     timestamp_force toolchain unpack
     timestamp_force toolchain verify
 fi
@@ -363,6 +356,13 @@
     timestamp_clear gdbserver
 fi
 
+# checks, we need more checks..
+mkdir -p $PACKAGE_OUT
+if [ $? != 0 ] ; then
+    echo "Can't create download/archive directory for toolchain tarballs"
+    exit 2
+fi
+
 download_package toolchain
 unpack_package   toolchain $ANDROID_TOOLCHAIN_SRC
 
diff --git a/pdk/doxygen_config/header.html b/pdk/doxygen_config/header.html
index b26c303..794041a 100644
--- a/pdk/doxygen_config/header.html
+++ b/pdk/doxygen_config/header.html
@@ -6,10 +6,10 @@
 <link href="doxygen.css" rel="stylesheet" type="text/css" />
 <style type="text/css">
 <!--
-.navigation {
+.tabs {
 	display: none;
 }
 -->
 </style>
 </head>
-<body>
\ No newline at end of file
+<body>
diff --git a/testrunner/.gitignore b/testrunner/.gitignore
new file mode 100644
index 0000000..0d20b64
--- /dev/null
+++ b/testrunner/.gitignore
@@ -0,0 +1 @@
+*.pyc
diff --git a/testrunner/run_command.py b/testrunner/run_command.py
index a98a943..ead80f1 100755
--- a/testrunner/run_command.py
+++ b/testrunner/run_command.py
@@ -145,7 +145,20 @@
       print subproc.communicate()[0]
     return subproc.returncode
   else:
+    # Need the full path to valgrind to avoid other versions on the system.
     subproc = subprocess.Popen(["/usr/bin/valgrind", "-q", full_path],
                                stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
     subproc.wait()
     return subproc.returncode
+
+
+def HasValgrind():
+  """Check that /usr/bin/valgrind exists.
+
+  We look for the fullpath to avoid picking up 'alternative' valgrind
+  on the system.
+
+  Returns:
+    True if a system valgrind was found.
+  """
+  return os.path.exists("/usr/bin/valgrind")
diff --git a/testrunner/runtest.py b/testrunner/runtest.py
index a87f9b5..05d29ec 100755
--- a/testrunner/runtest.py
+++ b/testrunner/runtest.py
@@ -369,10 +369,13 @@
       if run_command.RunHostCommand(f) != 0:
         logger.Log("%s... failed" % f)
       else:
-        if run_command.RunHostCommand(f, valgrind=True) == 0:
-          logger.Log("%s... ok\t\t[valgrind: ok]" % f)
+        if run_command.HasValgrind():
+          if run_command.RunHostCommand(f, valgrind=True) == 0:
+            logger.Log("%s... ok\t\t[valgrind: ok]" % f)
+          else:
+            logger.Log("%s... ok\t\t[valgrind: failed]" % f)
         else:
-          logger.Log("%s... ok\t\t[valgrind: failed]" % f)
+          logger.Log("%s... ok\t\t[valgrind: missing]" % f)
 
     # Run on the device
     logger.Log("\nRunning on target")
@@ -380,9 +383,15 @@
       full_path = os.path.join(os.sep, "system", "bin", f)
 
       # Single quotes are needed to prevent the shell splitting it.
-      status = self._adb.SendShellCommand("'%s >/dev/null 2>&1;echo -n $?'" %
+      output = self._adb.SendShellCommand("'%s 2>&1;echo -n exit code:$?'" %
                                           full_path)
-      logger.Log("%s... %s" % (f, status == "0" and "ok" or "failed"))
+      success = output.endswith("exit code:0")
+      logger.Log("%s... %s" % (f, success and "ok" or "failed"))
+      # Print the captured output when the test failed.
+      if not success or self._options.verbose:
+        pos = output.rfind("exit code")
+        output = output[0:pos]
+        logger.Log(output)
 
       # Cleanup
       self._adb.SendShellCommand("rm %s" % full_path)
diff --git a/tools/ddms/libs/ddmlib/src/com/android/ddmlib/AndroidDebugBridge.java b/tools/ddms/libs/ddmlib/src/com/android/ddmlib/AndroidDebugBridge.java
index 0957171..c587b4e 100644
--- a/tools/ddms/libs/ddmlib/src/com/android/ddmlib/AndroidDebugBridge.java
+++ b/tools/ddms/libs/ddmlib/src/com/android/ddmlib/AndroidDebugBridge.java
@@ -37,7 +37,7 @@
  * <p/><b>{@link #init(boolean)} must be called before anything is done.</b>
  */
 public final class AndroidDebugBridge {
-    
+
     /*
      * Minimum and maximum version of adb supported. This correspond to
      * ADB_SERVER_VERSION found in //device/tools/adb/adb.h
@@ -48,7 +48,7 @@
 
     private final static Pattern sAdbVersion = Pattern.compile(
             "^.*(\\d+)\\.(\\d+)\\.(\\d+)$"); //$NON-NLS-1$
-    
+
     private final static String ADB = "adb"; //$NON-NLS-1$
     private final static String DDMS = "ddms"; //$NON-NLS-1$
 
@@ -212,7 +212,7 @@
             monitorThread.quit();
         }
     }
-    
+
     /**
      * Returns whether the ddmlib is setup to support monitoring and interacting with
      * {@link Client}s running on the {@link Device}s.
@@ -220,7 +220,7 @@
     static boolean getClientSupport() {
         return sClientSupport;
     }
-    
+
     /**
      * Creates a {@link AndroidDebugBridge} that is not linked to any particular executable.
      * <p/>This bridge will expect adb to be running. It will not be able to start/stop/restart
@@ -325,6 +325,7 @@
 
     /**
      * Disconnects the current debug bridge, and destroy the object.
+     * <p/>This also stops the current adb host server.
      * <p/>
      * A new object will have to be created with {@link #createBridge(String, boolean)}.
      */
@@ -454,21 +455,21 @@
 
         return new Device[0];
     }
-    
+
     /**
      * Returns whether the bridge has acquired the initial list from adb after being created.
      * <p/>Calling {@link #getDevices()} right after {@link #createBridge(String, boolean)} will
      * generally result in an empty list. This is due to the internal asynchronous communication
      * mechanism with <code>adb</code> that does not guarantee that the {@link Device} list has been
      * built before the call to {@link #getDevices()}.
-     * <p/>The recommended way to get the list of {@link Device} objects is to create a 
+     * <p/>The recommended way to get the list of {@link Device} objects is to create a
      * {@link IDeviceChangeListener} object.
      */
     public boolean hasInitialDeviceList() {
         if (mDeviceMonitor != null) {
             return mDeviceMonitor.hasInitialDeviceList();
         }
-        
+
         return false;
     }
 
@@ -515,7 +516,7 @@
         }
         return -1;
     }
-    
+
     /**
      * Creates a new bridge.
      * @param osLocation the location of the command line tool
@@ -529,7 +530,7 @@
 
         checkAdbVersion();
     }
-    
+
     /**
      * Creates a new bridge not linked to any particular adb executable.
      */
@@ -591,7 +592,7 @@
                 Log.logAndDisplay(LogLevel.ERROR, ADB,
                         "Failed to parse the output of 'adb version'"); //$NON-NLS-1$
             }
-            
+
         } catch (IOException e) {
             Log.logAndDisplay(LogLevel.ERROR, ADB,
                     "Failed to get the adb version: " + e.getMessage()); //$NON-NLS-1$
@@ -609,7 +610,7 @@
      * <p/>
      * Returns true when a version number has been found so that we can stop scanning,
      * whether the version number is in the acceptable range or not.
-     * 
+     *
      * @param line The line to scan.
      * @return True if a version number was found (whether it is acceptable or not).
      */
@@ -666,7 +667,7 @@
     }
 
    /**
-     * Kills the debug bridge.
+     * Kills the debug bridge, and the adb host server.
      * @return true if success
      */
     boolean stop() {
@@ -740,7 +741,7 @@
             listenersCopy = sDeviceListeners.toArray(
                     new IDeviceChangeListener[sDeviceListeners.size()]);
         }
-        
+
         // Notify the listeners
         for (IDeviceChangeListener listener : listenersCopy) {
             // we attempt to catch any exception so that a bad listener doesn't kill our
@@ -776,7 +777,7 @@
             listenersCopy = sDeviceListeners.toArray(
                     new IDeviceChangeListener[sDeviceListeners.size()]);
         }
-        
+
         // Notify the listeners
         for (IDeviceChangeListener listener : listenersCopy) {
             // we attempt to catch any exception so that a bad listener doesn't kill our
@@ -812,7 +813,7 @@
             listenersCopy = sDeviceListeners.toArray(
                     new IDeviceChangeListener[sDeviceListeners.size()]);
         }
-        
+
         // Notify the listeners
         for (IDeviceChangeListener listener : listenersCopy) {
             // we attempt to catch any exception so that a bad listener doesn't kill our
@@ -848,7 +849,7 @@
         synchronized (sLock) {
             listenersCopy = sClientListeners.toArray(
                     new IClientChangeListener[sClientListeners.size()]);
-            
+
         }
 
         // Notify the listeners
@@ -962,7 +963,7 @@
      * @param errorOutput The array to store the stderr output. cannot be null.
      * @param stdOutput The array to store the stdout output. cannot be null.
      * @param displayStdOut If true this will display stdout as well
-     * @param waitforReaders if true, this will wait for the reader threads. 
+     * @param waitforReaders if true, this will wait for the reader threads.
      * @return the process return code.
      * @throws InterruptedException
      */
diff --git a/tools/ddms/libs/ddmlib/src/com/android/ddmlib/Device.java b/tools/ddms/libs/ddmlib/src/com/android/ddmlib/Device.java
index 0e7f0bb..37b33cf 100644
--- a/tools/ddms/libs/ddmlib/src/com/android/ddmlib/Device.java
+++ b/tools/ddms/libs/ddmlib/src/com/android/ddmlib/Device.java
@@ -208,7 +208,7 @@
      * (non-Javadoc)
      * @see com.android.ddmlib.IDevice#getSyncService()
      */
-    public SyncService getSyncService() {
+    public SyncService getSyncService() throws IOException {
         SyncService syncService = new SyncService(AndroidDebugBridge.sSocketAddr, this);
         if (syncService.openSync()) {
             return syncService;
diff --git a/tools/ddms/libs/ddmlib/src/com/android/ddmlib/IDevice.java b/tools/ddms/libs/ddmlib/src/com/android/ddmlib/IDevice.java
index 5dbce92..a54af8a 100755
--- a/tools/ddms/libs/ddmlib/src/com/android/ddmlib/IDevice.java
+++ b/tools/ddms/libs/ddmlib/src/com/android/ddmlib/IDevice.java
@@ -118,9 +118,11 @@
 
     /**
      * Returns a {@link SyncService} object to push / pull files to and from the device.
-     * @return <code>null</code> if the SyncService couldn't be created.
+     * @return <code>null</code> if the SyncService couldn't be created. This can happen if abd
+     * refuse to open the connection because the {@link IDevice} is invalid (or got disconnected).
+     * @throws IOException if the connection with adb failed.
      */
-    public SyncService getSyncService();
+    public SyncService getSyncService() throws IOException;
 
     /**
      * Returns a {@link FileListingService} for this device.
diff --git a/tools/ddms/libs/ddmlib/src/com/android/ddmlib/SyncService.java b/tools/ddms/libs/ddmlib/src/com/android/ddmlib/SyncService.java
index 44df000..c1d1d3b 100644
--- a/tools/ddms/libs/ddmlib/src/com/android/ddmlib/SyncService.java
+++ b/tools/ddms/libs/ddmlib/src/com/android/ddmlib/SyncService.java
@@ -209,9 +209,11 @@
 
     /**
      * Opens the sync connection. This must be called before any calls to push[File] / pull[File].
-     * @return true if the connection opened, false otherwise.
+     * @return true if the connection opened, false if adb refuse the connection. This can happen
+     * if the {@link Device} is invalid.
+     * @throws IOException If the connection to adb failed.
      */
-    boolean openSync() {
+    boolean openSync() throws IOException {
         try {
             mChannel = SocketChannel.open(mAddress);
             mChannel.configureBlocking(false);
@@ -236,13 +238,15 @@
             if (mChannel != null) {
                 try {
                     mChannel.close();
-                } catch (IOException e1) {
-                    // we do nothing, since we'll return false just below
+                } catch (IOException e2) {
+                    // we want to throw the original exception, so we ignore this one.
                 }
                 mChannel = null;
-                return false;
             }
+
+            throw e;
         }
+
         return true;
     }
 
diff --git a/tools/ddms/libs/ddmuilib/src/com/android/ddmuilib/explorer/DeviceExplorer.java b/tools/ddms/libs/ddmuilib/src/com/android/ddmuilib/explorer/DeviceExplorer.java
index ba0f555..34f575f 100644
--- a/tools/ddms/libs/ddmuilib/src/com/android/ddmuilib/explorer/DeviceExplorer.java
+++ b/tools/ddms/libs/ddmuilib/src/com/android/ddmuilib/explorer/DeviceExplorer.java
@@ -374,13 +374,13 @@
 
             }
         }.start();
-        
+
         return mTree;
     }
-    
+
     @Override
     protected void postCreation() {
-        
+
     }
 
     /**
@@ -418,61 +418,67 @@
         }
 
         // download the files
-        SyncService sync = mCurrentDevice.getSyncService();
-        if (sync != null) {
-            ISyncProgressMonitor monitor = SyncService.getNullProgressMonitor();
-            SyncResult result = sync.pullFile(keyEntry, keyFile.getAbsolutePath(), monitor);
-            if (result.getCode() != SyncService.RESULT_OK) {
-                DdmConsole.printErrorToConsole(String.format(
-                        "Failed to pull %1$s: %2$s", keyEntry.getName(), result.getMessage()));
-                return;
-            }
+        try {
+            SyncService sync = mCurrentDevice.getSyncService();
+            if (sync != null) {
+                ISyncProgressMonitor monitor = SyncService.getNullProgressMonitor();
+                SyncResult result = sync.pullFile(keyEntry, keyFile.getAbsolutePath(), monitor);
+                if (result.getCode() != SyncService.RESULT_OK) {
+                    DdmConsole.printErrorToConsole(String.format(
+                            "Failed to pull %1$s: %2$s", keyEntry.getName(), result.getMessage()));
+                    return;
+                }
 
-            result = sync.pullFile(dataEntry, dataFile.getAbsolutePath(), monitor);
-            if (result.getCode() != SyncService.RESULT_OK) {
-                DdmConsole.printErrorToConsole(String.format(
-                        "Failed to pull %1$s: %2$s", dataEntry.getName(), result.getMessage()));
-                return;
-            }
+                result = sync.pullFile(dataEntry, dataFile.getAbsolutePath(), monitor);
+                if (result.getCode() != SyncService.RESULT_OK) {
+                    DdmConsole.printErrorToConsole(String.format(
+                            "Failed to pull %1$s: %2$s", dataEntry.getName(), result.getMessage()));
+                    return;
+                }
 
-            // now that we have the file, we need to launch traceview
-            String[] command = new String[2];
-            command[0] = DdmUiPreferences.getTraceview();
-            command[1] = path + File.separator + baseName;
+                // now that we have the file, we need to launch traceview
+                String[] command = new String[2];
+                command[0] = DdmUiPreferences.getTraceview();
+                command[1] = path + File.separator + baseName;
 
-            try {
-                final Process p = Runtime.getRuntime().exec(command);
+                try {
+                    final Process p = Runtime.getRuntime().exec(command);
 
-                // create a thread for the output
-                new Thread("Traceview output") {
-                    @Override
-                    public void run() {
-                        // create a buffer to read the stderr output
-                        InputStreamReader is = new InputStreamReader(p.getErrorStream());
-                        BufferedReader resultReader = new BufferedReader(is);
+                    // create a thread for the output
+                    new Thread("Traceview output") {
+                        @Override
+                        public void run() {
+                            // create a buffer to read the stderr output
+                            InputStreamReader is = new InputStreamReader(p.getErrorStream());
+                            BufferedReader resultReader = new BufferedReader(is);
 
-                        // read the lines as they come. if null is returned, it's
-                        // because the process finished
-                        try {
-                            while (true) {
-                                String line = resultReader.readLine();
-                                if (line != null) {
-                                    DdmConsole.printErrorToConsole("Traceview: " + line);
-                                } else {
-                                    break;
+                            // read the lines as they come. if null is returned, it's
+                            // because the process finished
+                            try {
+                                while (true) {
+                                    String line = resultReader.readLine();
+                                    if (line != null) {
+                                        DdmConsole.printErrorToConsole("Traceview: " + line);
+                                    } else {
+                                        break;
+                                    }
                                 }
+                                // get the return code from the process
+                                p.waitFor();
+                            } catch (IOException e) {
+                            } catch (InterruptedException e) {
+
                             }
-                            // get the return code from the process
-                            p.waitFor();
-                        } catch (IOException e) {
-                        } catch (InterruptedException e) {
-
                         }
-                    }
-                }.start();
+                    }.start();
 
-            } catch (IOException e) {
+                } catch (IOException e) {
+                }
             }
+        } catch (IOException e) {
+            DdmConsole.printErrorToConsole(String.format(
+                    "Failed to pull %1$s: %2$s", keyEntry.getName(), e.getMessage()));
+            return;
         }
     }
 
@@ -667,21 +673,21 @@
      * @param localDirector the local directory in which to save the files.
      */
     private void pullSelection(TreeItem[] items, final String localDirectory) {
-        final SyncService sync = mCurrentDevice.getSyncService();
-        if (sync != null) {
-            // make a list of the FileEntry.
-            ArrayList<FileEntry> entries = new ArrayList<FileEntry>();
-            for (TreeItem item : items) {
-                Object data = item.getData();
-                if (data instanceof FileEntry) {
-                    entries.add((FileEntry)data);
+        try {
+            final SyncService sync = mCurrentDevice.getSyncService();
+            if (sync != null) {
+                // make a list of the FileEntry.
+                ArrayList<FileEntry> entries = new ArrayList<FileEntry>();
+                for (TreeItem item : items) {
+                    Object data = item.getData();
+                    if (data instanceof FileEntry) {
+                        entries.add((FileEntry)data);
+                    }
                 }
-            }
-            final FileEntry[] entryArray = entries.toArray(
-                    new FileEntry[entries.size()]);
+                final FileEntry[] entryArray = entries.toArray(
+                        new FileEntry[entries.size()]);
 
-            // get a progressdialog
-            try {
+                // get a progressdialog
                 new ProgressMonitorDialog(mParent.getShell()).run(true, true,
                         new IRunnableWithProgress() {
                     public void run(IProgressMonitor monitor)
@@ -699,13 +705,10 @@
                         sync.close();
                     }
                 });
-            } catch (InvocationTargetException e) {
-                DdmConsole.printErrorToConsole( "Failed to pull selection");
-                DdmConsole.printErrorToConsole(e.getMessage());
-            } catch (InterruptedException e) {
-                DdmConsole.printErrorToConsole("Failed to pull selection");
-                DdmConsole.printErrorToConsole(e.getMessage());
             }
+        } catch (Exception e) {
+            DdmConsole.printErrorToConsole( "Failed to pull selection");
+            DdmConsole.printErrorToConsole(e.getMessage());
         }
     }
 
@@ -715,9 +718,9 @@
      * @param local the destination filepath
      */
     private void pullFile(final FileEntry remote, final String local) {
-        final SyncService sync = mCurrentDevice.getSyncService();
-        if (sync != null) {
-            try {
+        try {
+            final SyncService sync = mCurrentDevice.getSyncService();
+            if (sync != null) {
                 new ProgressMonitorDialog(mParent.getShell()).run(true, true,
                         new IRunnableWithProgress() {
                     public void run(IProgressMonitor monitor)
@@ -734,13 +737,10 @@
                         sync.close();
                     }
                 });
-            } catch (InvocationTargetException e) {
-                DdmConsole.printErrorToConsole( "Failed to pull selection");
-                DdmConsole.printErrorToConsole(e.getMessage());
-            } catch (InterruptedException e) {
-                DdmConsole.printErrorToConsole("Failed to pull selection");
-                DdmConsole.printErrorToConsole(e.getMessage());
             }
+        } catch (Exception e) {
+            DdmConsole.printErrorToConsole( "Failed to pull selection");
+            DdmConsole.printErrorToConsole(e.getMessage());
         }
     }
 
@@ -750,9 +750,9 @@
      * @param remoteDirectory
      */
     private void pushFiles(final String[] localFiles, final FileEntry remoteDirectory) {
-        final SyncService sync = mCurrentDevice.getSyncService();
-        if (sync != null) {
-            try {
+        try {
+            final SyncService sync = mCurrentDevice.getSyncService();
+            if (sync != null) {
                 new ProgressMonitorDialog(mParent.getShell()).run(true, true,
                         new IRunnableWithProgress() {
                     public void run(IProgressMonitor monitor)
@@ -769,14 +769,10 @@
                         sync.close();
                     }
                 });
-            } catch (InvocationTargetException e) {
-                DdmConsole.printErrorToConsole("Failed to push the items");
-                DdmConsole.printErrorToConsole(e.getMessage());
-            } catch (InterruptedException e) {
-                DdmConsole.printErrorToConsole("Failed to push the items");
-                DdmConsole.printErrorToConsole(e.getMessage());
             }
-            return;
+        } catch (Exception e) {
+            DdmConsole.printErrorToConsole("Failed to push the items");
+            DdmConsole.printErrorToConsole(e.getMessage());
         }
     }
 
@@ -786,9 +782,9 @@
      * @param remoteDirectory the remote destination directory on the device
      */
     private void pushFile(final String local, final String remoteDirectory) {
-        final SyncService sync = mCurrentDevice.getSyncService();
-        if (sync != null) {
-            try {
+        try {
+            final SyncService sync = mCurrentDevice.getSyncService();
+            if (sync != null) {
                 new ProgressMonitorDialog(mParent.getShell()).run(true, true,
                         new IRunnableWithProgress() {
                     public void run(IProgressMonitor monitor)
@@ -812,14 +808,10 @@
                         sync.close();
                     }
                 });
-            } catch (InvocationTargetException e) {
-                DdmConsole.printErrorToConsole("Failed to push the item(s).");
-                DdmConsole.printErrorToConsole(e.getMessage());
-            } catch (InterruptedException e) {
-                DdmConsole.printErrorToConsole("Failed to push the item(s).");
-                DdmConsole.printErrorToConsole(e.getMessage());
             }
-            return;
+        } catch (Exception e) {
+            DdmConsole.printErrorToConsole("Failed to push the item(s).");
+            DdmConsole.printErrorToConsole(e.getMessage());
         }
     }
 
diff --git a/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdtPlugin.java b/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdtPlugin.java
index d3e3f44..0ac3bb9 100644
--- a/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdtPlugin.java
+++ b/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdtPlugin.java
@@ -1122,22 +1122,6 @@
                 "/icons/android.png"); //$NON-NLS-1$
         sAndroidLogo = sAndroidLogoDesc.createImage();
 
-        // get the stream to write in the android console.
-        MessageConsole androidConsole = AdtPlugin.getDefault().getAndroidConsole();
-        mAndroidConsoleStream = androidConsole.newMessageStream();
-
-        mAndroidConsoleErrorStream = androidConsole.newMessageStream();
-        mRed = new Color(getDisplay(), 0xFF, 0x00, 0x00);
-
-        // because this can be run, in some cases, by a non ui thread, and beccause
-        // changing the console properties update the ui, we need to make this change
-        // in the ui thread.
-        getDisplay().asyncExec(new Runnable() {
-            public void run() {
-                mAndroidConsoleErrorStream.setColor(mRed);
-            }
-        });
-
         // Add a resource listener to handle compiled resources.
         IWorkspace ws = ResourcesPlugin.getWorkspace();
         mResourceMonitor = ResourceMonitor.startMonitoring(ws);
diff --git a/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/AndroidLaunchController.java b/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/AndroidLaunchController.java
index e1d7f18..f178597 100644
--- a/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/AndroidLaunchController.java
+++ b/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/AndroidLaunchController.java
@@ -848,63 +848,70 @@
      * @return true if the install succeeded.
      */
     private boolean doSyncApp(DelayedLaunchInfo launchInfo, IDevice device) {
-        SyncService sync = device.getSyncService();
-        if (sync != null) {
-            IPath path = launchInfo.getPackageFile().getLocation();
-            String message = String.format("Uploading %1$s onto device '%2$s'",
-                    path.lastSegment(), device.getSerialNumber());
-            AdtPlugin.printToConsole(launchInfo.getProject(), message);
+        try {
+            SyncService sync = device.getSyncService();
+            if (sync != null) {
+                IPath path = launchInfo.getPackageFile().getLocation();
+                String message = String.format("Uploading %1$s onto device '%2$s'",
+                        path.lastSegment(), device.getSerialNumber());
+                AdtPlugin.printToConsole(launchInfo.getProject(), message);
 
-            String osLocalPath = path.toOSString();
-            String apkName = launchInfo.getPackageFile().getName();
-            String remotePath = "/data/local/tmp/" + apkName; //$NON-NLS-1$
+                String osLocalPath = path.toOSString();
+                String apkName = launchInfo.getPackageFile().getName();
+                String remotePath = "/data/local/tmp/" + apkName; //$NON-NLS-1$
 
-            SyncResult result = sync.pushFile(osLocalPath, remotePath,
-                    SyncService.getNullProgressMonitor());
+                SyncResult result = sync.pushFile(osLocalPath, remotePath,
+                        SyncService.getNullProgressMonitor());
 
-            if (result.getCode() != SyncService.RESULT_OK) {
-                String msg = String.format("Failed to upload %1$s on '%2$s': %3$s",
-                        apkName, device.getSerialNumber(), result.getMessage());
+                if (result.getCode() != SyncService.RESULT_OK) {
+                    String msg = String.format("Failed to upload %1$s on '%2$s': %3$s",
+                            apkName, device.getSerialNumber(), result.getMessage());
+                    AdtPlugin.printErrorToConsole(launchInfo.getProject(), msg);
+                    return false;
+                }
+
+                // Now that the package is uploaded, we can install it properly.
+                // This will check that there isn't another apk declaring the same package, or
+                // that another install used a different key.
+                boolean installResult =  installPackage(launchInfo, remotePath, device);
+
+                // now we delete the app we sync'ed
+                try {
+                    device.executeShellCommand("rm " + remotePath, new MultiLineReceiver() { //$NON-NLS-1$
+                        @Override
+                        public void processNewLines(String[] lines) {
+                            // pass
+                        }
+                        public boolean isCancelled() {
+                            return false;
+                        }
+                    });
+                } catch (IOException e) {
+                    AdtPlugin.printErrorToConsole(launchInfo.getProject(), String.format(
+                            "Failed to delete temporary package: %1$s", e.getMessage()));
+                    return false;
+                }
+
+                // if the installation succeeded, we register it.
+                if (installResult) {
+                    ApkInstallManager.getInstance().registerInstallation(
+                            launchInfo.getProject(), device);
+                }
+
+                return installResult;
+            } else {
+                String msg = String.format(
+                        "Failed to upload %1$s on device '%2$s': Unable to open sync connection!",
+                        launchInfo.getPackageFile().getName(), device.getSerialNumber());
                 AdtPlugin.printErrorToConsole(launchInfo.getProject(), msg);
-                return false;
             }
-
-            // Now that the package is uploaded, we can install it properly.
-            // This will check that there isn't another apk declaring the same package, or
-            // that another install used a different key.
-            boolean installResult =  installPackage(launchInfo, remotePath, device);
-
-            // now we delete the app we sync'ed
-            try {
-                device.executeShellCommand("rm " + remotePath, new MultiLineReceiver() { //$NON-NLS-1$
-                    @Override
-                    public void processNewLines(String[] lines) {
-                        // pass
-                    }
-                    public boolean isCancelled() {
-                        return false;
-                    }
-                });
-            } catch (IOException e) {
-                AdtPlugin.printErrorToConsole(launchInfo.getProject(), String.format(
-                        "Failed to delete temporary package: %1$s", e.getMessage()));
-                return false;
-            }
-
-            // if the installation succeeded, we register it.
-            if (installResult) {
-                ApkInstallManager.getInstance().registerInstallation(
-                        launchInfo.getProject(), device);
-            }
-
-            return installResult;
+        } catch (IOException e) {
+            String msg = String.format(
+                    "Failed to upload %1$s on device '%2$s': Unable to open sync connection!",
+                    launchInfo.getPackageFile().getName(), device.getSerialNumber());
+            AdtPlugin.printErrorToConsole(launchInfo.getProject(), msg, e.getMessage());
         }
 
-        String msg = String.format(
-                "Failed to upload %1$s on device '%2$s': Unable to open sync connection!",
-                launchInfo.getPackageFile().getName(), device.getSerialNumber());
-        AdtPlugin.printErrorToConsole(launchInfo.getProject(), msg);
-
         return false;
     }