aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Gampe <agampe@google.com>2018-01-22 20:08:17 +0000
committerandroid-build-merger <android-build-merger@google.com>2018-01-22 20:08:17 +0000
commita3c9c3caed216b8076efe7a2c4865c1f2622e361 (patch)
tree35c28079f4c7b251b91bedfaccbf80ccaba506bc
parentd752efb4a4601d18c013015136c55e9010986247 (diff)
parentcd4ecbe5890d58d919eb2299214403b7ce84695d (diff)
downloaddexmaker-a3c9c3caed216b8076efe7a2c4865c1f2622e361.tar.gz
Merge "Dexmaker: Update attachJvmtiAgent API use" am: b599ccd3c0 am: ebf435f931
am: cd4ecbe589 Change-Id: I0c792f84051aa36719e8c4bb57da32c10683aa1a
-rw-r--r--dexmaker-mockito-inline/src/main/java/com/android/dx/mockito/inline/JvmtiAgent.java26
1 files changed, 4 insertions, 22 deletions
diff --git a/dexmaker-mockito-inline/src/main/java/com/android/dx/mockito/inline/JvmtiAgent.java b/dexmaker-mockito-inline/src/main/java/com/android/dx/mockito/inline/JvmtiAgent.java
index 1b4a550..aca7a0c 100644
--- a/dexmaker-mockito-inline/src/main/java/com/android/dx/mockito/inline/JvmtiAgent.java
+++ b/dexmaker-mockito-inline/src/main/java/com/android/dx/mockito/inline/JvmtiAgent.java
@@ -34,7 +34,7 @@ import dalvik.system.BaseDexClassLoader;
* Interface to the native jvmti agent in agent.cc
*/
class JvmtiAgent {
- private static final String AGENT_LIB_NAME = "dexmakerjvmtiagent";
+ private static final String AGENT_LIB_NAME = "libdexmakerjvmtiagent.so";
private static final Object lock = new Object();
@@ -65,32 +65,14 @@ class JvmtiAgent {
+ "by a BaseDexClassLoader");
}
- // Currently Debug.attachJvmtiAgent requires a file in the right directory
- File copiedAgent = File.createTempFile("agent", ".so");
- copiedAgent.deleteOnExit();
-
- try (InputStream is = new FileInputStream(
- ((BaseDexClassLoader) cl).findLibrary(AGENT_LIB_NAME))) {
- try (OutputStream os = new FileOutputStream(copiedAgent)) {
- byte[] buffer = new byte[64 * 1024];
-
- while (true) {
- int numRead = is.read(buffer);
- if (numRead == -1) {
- break;
- }
- os.write(buffer, 0, numRead);
- }
- }
- }
-
try {
/*
* TODO (moltmann@google.com): Replace with regular method call once the API becomes
* public
*/
Class.forName("android.os.Debug").getMethod("attachJvmtiAgent", String.class,
- String.class).invoke(null, copiedAgent.getAbsolutePath(), null);
+ String.class, ClassLoader.class).invoke(null, AGENT_LIB_NAME,
+ null, cl);
} catch (InvocationTargetException e) {
loadJvmtiException = e.getCause();
} catch (IllegalAccessException | ClassNotFoundException | NoSuchMethodException e) {
@@ -99,7 +81,7 @@ class JvmtiAgent {
if (loadJvmtiException != null) {
if (loadJvmtiException instanceof IOException) {
- throw (IOException)loadJvmtiException;
+ throw new IOException(cl.toString(), loadJvmtiException);
} else {
throw new IOException("Could not load jvmti plugin",
loadJvmtiException);