aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ddms/libs/ddmlib/src/com/android/ddmlib/AndroidDebugBridge.java7
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.hierarchyviewer/src/com/android/ide/eclipse/hierarchyviewer/HierarchyViewerPlugin.java17
-rw-r--r--hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/HierarchyViewerDirector.java18
-rw-r--r--hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/device/DeviceBridge.java34
4 files changed, 65 insertions, 11 deletions
diff --git a/ddms/libs/ddmlib/src/com/android/ddmlib/AndroidDebugBridge.java b/ddms/libs/ddmlib/src/com/android/ddmlib/AndroidDebugBridge.java
index c62ce42..01cdf0a 100644
--- a/ddms/libs/ddmlib/src/com/android/ddmlib/AndroidDebugBridge.java
+++ b/ddms/libs/ddmlib/src/com/android/ddmlib/AndroidDebugBridge.java
@@ -61,6 +61,7 @@ public final class AndroidDebugBridge {
private static InetSocketAddress sSocketAddr;
private static AndroidDebugBridge sThis;
+ private static boolean sInitialized = false;
private static boolean sClientSupport;
/** Full path to adb. */
@@ -173,7 +174,11 @@ public final class AndroidDebugBridge {
* @see AndroidDebugBridge#createBridge(String, boolean)
* @see DdmPreferences
*/
- public static void init(boolean clientSupport) {
+ public static synchronized void init(boolean clientSupport) {
+ if (sInitialized) {
+ throw new IllegalStateException("AndroidDebugBridge.init() has already been called.");
+ }
+ sInitialized = true;
sClientSupport = clientSupport;
// Determine port and instantiate socket address.
diff --git a/eclipse/plugins/com.android.ide.eclipse.hierarchyviewer/src/com/android/ide/eclipse/hierarchyviewer/HierarchyViewerPlugin.java b/eclipse/plugins/com.android.ide.eclipse.hierarchyviewer/src/com/android/ide/eclipse/hierarchyviewer/HierarchyViewerPlugin.java
index 8f94c65..959bf6c 100644
--- a/eclipse/plugins/com.android.ide.eclipse.hierarchyviewer/src/com/android/ide/eclipse/hierarchyviewer/HierarchyViewerPlugin.java
+++ b/eclipse/plugins/com.android.ide.eclipse.hierarchyviewer/src/com/android/ide/eclipse/hierarchyviewer/HierarchyViewerPlugin.java
@@ -58,7 +58,7 @@ public class HierarchyViewerPlugin extends AbstractUIPlugin {
public void start(BundleContext context) throws Exception {
super.start(context);
sPlugin = this;
-
+
// set the consoles.
final MessageConsole messageConsole = new MessageConsole("Hierarchy Viewer", null); //$NON-NLS-1$
@@ -115,9 +115,10 @@ public class HierarchyViewerPlugin extends AbstractUIPlugin {
new Thread() {
@Override
public void run() {
- director.initDebugBridge();
- director.startListenForDevices();
- director.populateDeviceSelectionModel();
+ if (director.acquireBridge()) {
+ director.startListenForDevices();
+ director.populateDeviceSelectionModel();
+ }
}
}.start();
}
@@ -143,7 +144,7 @@ public class HierarchyViewerPlugin extends AbstractUIPlugin {
/**
* Returns the shared instance
- *
+ *
* @return the shared instance
*/
public static HierarchyViewerPlugin getPlugin() {
@@ -152,7 +153,7 @@ public class HierarchyViewerPlugin extends AbstractUIPlugin {
/**
* Set the location of the adb executable and optionally starts adb
- *
+ *
* @param adb location of adb
* @param startAdb flag to start adb
*/
@@ -177,7 +178,7 @@ public class HierarchyViewerPlugin extends AbstractUIPlugin {
/**
* Prints a message, associated with a project to the specified stream
- *
+ *
* @param stream The stream to write to
* @param tag The tag associated to the message. Can be null
* @param message The message to print.
@@ -192,7 +193,7 @@ public class HierarchyViewerPlugin extends AbstractUIPlugin {
/**
* Creates a string containing the current date/time, and the tag
- *
+ *
* @param tag The tag associated to the message. Can be null
* @return The dateTag
*/
diff --git a/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/HierarchyViewerDirector.java b/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/HierarchyViewerDirector.java
index 63b30c0..f397b1f 100644
--- a/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/HierarchyViewerDirector.java
+++ b/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/HierarchyViewerDirector.java
@@ -17,6 +17,7 @@
package com.android.hierarchyviewerlib;
import com.android.ddmlib.AdbCommandRejectedException;
+import com.android.ddmlib.AndroidDebugBridge;
import com.android.ddmlib.IDevice;
import com.android.ddmlib.Log;
import com.android.ddmlib.RawImage;
@@ -88,6 +89,21 @@ public abstract class HierarchyViewerDirector implements IDeviceChangeListener,
return sDirector;
}
+ /**
+ * Init the DeviceBridge with an existing {@link AndroidDebugBridge}. This loops until
+ * a bridge exists or a timeout is reached.
+ */
+ public boolean acquireBridge() {
+ return DeviceBridge.acquireBridge();
+ }
+
+ /**
+ * Creates an {@link AndroidDebugBridge} connected to adb at the given location.
+ *
+ * If a bridge is already running, this disconnects it and creates a new one.
+ *
+ * @param adbLocation the location to adb.
+ */
public void initDebugBridge() {
DeviceBridge.initDebugBridge(getAdbLocation());
}
@@ -633,7 +649,7 @@ public abstract class HierarchyViewerDirector implements IDeviceChangeListener,
}
}
}
-
+
public void setPixelPerfectAutoRefreshInterval(int value) {
synchronized (mPixelPerfectRefreshTimer) {
if (mPixelPerfectAutoRefreshInterval == value) {
diff --git a/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/device/DeviceBridge.java b/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/device/DeviceBridge.java
index 20feeec..74fbc13 100644
--- a/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/device/DeviceBridge.java
+++ b/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/device/DeviceBridge.java
@@ -80,6 +80,37 @@ public class DeviceBridge {
}
}
+ /**
+ * Init the DeviceBridge with an existing {@link AndroidDebugBridge}. This loops until
+ * a bridge exists or a timeout is reached.
+ */
+ public static boolean acquireBridge() {
+ int count = 10;
+ do {
+ sBridge = AndroidDebugBridge.getBridge();
+ if (sBridge == null) {
+ try {
+ Thread.sleep(500);
+ count--;
+ if (count == 0) {
+ return false;
+ }
+ } catch (InterruptedException e) {
+ // pass
+ }
+ }
+ } while (sBridge == null);
+
+ return true;
+ }
+
+ /**
+ * Creates an {@link AndroidDebugBridge} connected to adb at the given location.
+ *
+ * If a bridge is already running, this disconnects it and creates a new one.
+ *
+ * @param adbLocation the location to adb.
+ */
public static void initDebugBridge(String adbLocation) {
if (sBridge == null) {
AndroidDebugBridge.init(false /* debugger support */);
@@ -89,6 +120,7 @@ public class DeviceBridge {
}
}
+ /** Disconnects the current {@link AndroidDebugBridge}. */
public static void terminate() {
AndroidDebugBridge.terminate();
}
@@ -117,7 +149,7 @@ public class DeviceBridge {
* <p/>
* This starts a port forwarding between a local port and a port on the
* device.
- *
+ *
* @param device
*/
public static void setupDeviceForward(IDevice device) {