summaryrefslogtreecommitdiff
path: root/core/java/android/app/ActivityThread.java
diff options
context:
space:
mode:
authorAlex Light <allight@google.com>2019-08-12 10:58:29 -0700
committerAlex Light <allight@google.com>2019-08-14 15:32:12 -0700
commit330e8be6044b395846c28cf44543ce8a8cace272 (patch)
treececf6db1413840952dd8345b3259653b99fce0bc /core/java/android/app/ActivityThread.java
parentb7e133be72e32197c0fc474e1caf261e7768efc0 (diff)
Add agent startup-attach
Add ability to give 'startup-agents' that are automatically loaded when a (debuggable) app starts. These agents are any files in the 'code_cache/startup_agents' directory. The agents are started with the apps data_directory as an argument. Test: Install debuggable apk (here com.antonioleiva.bandhookkotlin) walleye:/ $ run-as com.antonioleiva.bandhookkotlin sh walleye:/data/data/com.antonioleiva.bandhookkotlin $ mkdir code_cache/startup_agents walleye:/data/data/com.antonioleiva.bandhookkotlin $ cp /data/local/tmp/libtifasts32.so code_cache walleye:/data/data/com.antonioleiva.bandhookkotlin $ cp /data/local/tmp/libtifasts64.so code_cache walleye:/data/data/com.antonioleiva.bandhookkotlin $ cp /data/local/tmp/libchainagentss32.so code_cache/startup_agents/ walleye:/data/data/com.antonioleiva.bandhookkotlin $ cp /data/local/tmp/libchainagentss64.so code_cache/startup_agents/ walleye:/data/data/com.antonioleiva.bandhookkotlin $ echo $PWD/code_cache/libtifasts32.so=log,ClassLoad > chain_agents.txt walleye:/data/data/com.antonioleiva.bandhookkotlin $ echo $PWD/code_cache/libtifasts64.so=log,ClassLoad >> chain_agents.txt Start bandhookkotlin Examine logcat Bug: 135627501 Change-Id: Ib82b27df90c7964a995288d8b2b3d348a11cdd80 (cherry picked from commit c0fce111c8b7c68ddb397ac7c65ac5c35a40da01)
Diffstat (limited to 'core/java/android/app/ActivityThread.java')
-rw-r--r--core/java/android/app/ActivityThread.java22
1 files changed, 22 insertions, 0 deletions
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index 553ef69fe8e2..a6784780d72f 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -191,6 +191,8 @@ import java.io.PrintWriter;
import java.lang.ref.WeakReference;
import java.lang.reflect.Method;
import java.net.InetAddress;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Arrays;
@@ -6435,6 +6437,26 @@ public final class ActivityThread extends ClientTransactionHandler {
NetworkSecurityConfigProvider.install(appContext);
Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
+
+ if (isAppDebuggable) {
+ try {
+ // Load all the agents in the code_cache/startup_agents directory.
+ // We pass the absolute path to the data_dir as an argument.
+ Path startup_path = appContext.getCodeCacheDir().toPath().resolve("startup_agents");
+ if (Files.exists(startup_path)) {
+ for (Path p : Files.newDirectoryStream(startup_path)) {
+ handleAttachAgent(
+ p.toAbsolutePath().toString()
+ + "="
+ + appContext.getDataDir().toPath().toAbsolutePath().toString(),
+ data.info);
+ }
+ }
+ } catch (Exception e) {
+ // Ignored.
+ }
+ }
+
// Continue loading instrumentation.
if (ii != null) {
ApplicationInfo instrApp;