From a80e4dc30f8148d09cb46d98465d917bbe81d08f Mon Sep 17 00:00:00 2001 From: Bill Napier Date: Mon, 18 Oct 2010 13:42:29 -0700 Subject: Integrate 17398174 into tools_r8. DO NOT MERGE. Make MonkeyRunner's adb finding more robust. This includes fixes for running out of the SDK. Change-Id: Ie73ccd391b34f8a75f23738a97c42902f91af841 --- monkeyrunner/etc/monkeyrunner.bat | 2 +- monkeyrunner/src/Android.mk | 4 +++- .../com/android/monkeyrunner/adb/AdbBackend.java | 27 +++++++++++++++++++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/monkeyrunner/etc/monkeyrunner.bat b/monkeyrunner/etc/monkeyrunner.bat index e927d08..1cf38ca 100644 --- a/monkeyrunner/etc/monkeyrunner.bat +++ b/monkeyrunner/etc/monkeyrunner.bat @@ -43,4 +43,4 @@ if exist %frameworkdir%%jarfile% goto JarFileOk set jarpath=%frameworkdir%%jarfile% -call %java_exe% -Xmx512m -Djava.ext.dirs=%frameworkdir% -jar %jarpath% %* +call %java_exe% -Xmx512m -Djava.ext.dirs=%frameworkdir% -Dcom.android.monkeyrunner.bindir=..\framework -jar %jarpath% %* diff --git a/monkeyrunner/src/Android.mk b/monkeyrunner/src/Android.mk index 11c7cc0..38be272 100644 --- a/monkeyrunner/src/Android.mk +++ b/monkeyrunner/src/Android.mk @@ -23,7 +23,9 @@ LOCAL_JAVA_LIBRARIES := \ ddmlib \ jython \ guavalib \ - jsilver + jsilver \ + sdklib + LOCAL_JAVA_RESOURCE_DIRS := resources LOCAL_MODULE := monkeyrunner diff --git a/monkeyrunner/src/com/android/monkeyrunner/adb/AdbBackend.java b/monkeyrunner/src/com/android/monkeyrunner/adb/AdbBackend.java index b9549a3..455d131 100644 --- a/monkeyrunner/src/com/android/monkeyrunner/adb/AdbBackend.java +++ b/monkeyrunner/src/com/android/monkeyrunner/adb/AdbBackend.java @@ -21,7 +21,9 @@ import com.android.ddmlib.AndroidDebugBridge; import com.android.ddmlib.IDevice; import com.android.monkeyrunner.MonkeyDevice; import com.android.monkeyrunner.MonkeyRunnerBackend; +import com.android.sdklib.SdkConstants; +import java.io.File; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -39,10 +41,33 @@ public class AdbBackend implements MonkeyRunnerBackend { private final AndroidDebugBridge bridge; public AdbBackend() { + // [try to] ensure ADB is running + String adbLocation = findAdb(); + AndroidDebugBridge.init(false /* debugger support */); bridge = AndroidDebugBridge.createBridge( - "adb", true /* forceNewBridge */); + adbLocation, true /* forceNewBridge */); + } + + private String findAdb() { + String mrParentLocation = + System.getProperty("com.android.monkeyrunner.bindir"); //$NON-NLS-1$ + + // in the new SDK, adb is in the platform-tools, but when run from the command line + // in the Android source tree, then adb is next to monkeyrunner. + if (mrParentLocation != null && mrParentLocation.length() != 0) { + // check if there's a platform-tools folder + File platformTools = new File(new File(mrParentLocation).getParent(), + SdkConstants.FD_PLATFORM_TOOLS); + if (platformTools.isDirectory()) { + return platformTools.getAbsolutePath() + File.separator + SdkConstants.FN_ADB; + } + + return mrParentLocation + File.separator + SdkConstants.FN_ADB; + } + + return SdkConstants.FN_ADB; } /** -- cgit v1.1