tree: 01fb3493fc26dcd9d89b0aab2b14f8d5f5d566b1 [path history] [tgz]
  1. src/
  2. android.sdktools.aspects_agent.iml
  3. BUILD
  4. jarjar_rules.txt

Aspects agent


This is a java agent that allows to add functionality to methods in the loaded classes. In order to use it, simply add the -javaagent option as follows


Make sure that the name of the jar file matches the given in the example. After the equals, the agent expects the rules file.

The rules file

The rules file defines which methods should be intercepted and the method to be called when the method is called. This allows for additional checks or logging to be added.

An example of rules file would be:;

In this case, when method getInputStream of HttpURLConnection, the static method will be called. Since is a common source of methods, if you omit it, this will be the default class used by the rules file.

If you do not want to intercept only a specific signature but all the methods with the name name, you can just use the simplified signature and not add the paramters and return type. The example above would end up as:;

This file defines a few common assertions.

Method nameUsage
assertIsNotEdtThis method will throw a RuntimeException if the method is called on the EDT
assertIsEdtThis method will throw a RuntimeException if the method is NOT called on the EDT
warnPrints a string to System.err when this method is called
dumpStackTracePrints the current stack trace to System.err

Defining your own assertions

The only requirement for the methods are to be public and static. As long as they are part of the classpath, they can be invoked by the agent.

Sample rules file

# Network

# Long I/O

# VFS Methods

How to build the agent

Use bazel to build the agent:

bazel build //tools/base/aspects-agent:aspects_agent

Now the agent is located at: