The changelogging tool is a code generation utility designed to automatically instrument Java source files to track and log changes to specific fields.
The tool scans input Java files for classes annotated with @TrackedType and fields annotated with @TrackedField. For these annotated elements, it:
This automation makes it easy to track and log state changes within complex object graphs, e.g. the WindowManager hierarchy.
The tool can be executed via command line with the following options:
changelogging [--classpath <paths>] --out-srcjar <output.srcjar> [--packages <pkg1,pkg2,...>] [--emit-companion-classes] [--noop] <input.srcjar> changelogging [--classpath <paths>] --out-srcjar <output.srcjar> [--packages <pkg1,pkg2,...>] [--emit-companion-classes] [--noop] [<input.java>, ...]
--classpath <paths>: A list of paths (jars or directories) containing dependencies of the input files, separated by the system path separator (e.g., : on Linux/macOS, ; on Windows). This is crucial for resolving types during analysis.--out-srcjar <output.srcjar>: The path to the output .srcjar file where the transformed source files will be written. This argument is required.--packages <pkg1,pkg2,...>: Optional comma-separated list of packages to instrument. When provided, only .java files whose package ...; declaration matches one of the specified packages (or any of their subpackages) will undergo AST analysis and transformation; all other .java files and non-Java files are copied directly to the output .srcjar without modification. As a safety guardrail, if any skipped .java file contains @TrackedType or @TrackedField annotations, the tool will abort with an error.--emit-companion-classes: Optional flag. When provided, the tool generates companion classes for non-instrumentable types (e.g. android.graphics.Rect) and writes them to the output .srcjar. This flag should be enabled in exactly one module invocation (e.g. in core/java/Android.bp) to avoid duplicate class definitions.--noop: Optional flag. If provided, the tool runs in “no-operation” mode, simply copying the input files to the output .srcjar without applying any transformations.<input.srcjar> | <input.java> ...: The input files to process. This can be a single .srcjar file containing Java sources, or a list of individual .java files.The following diagram illustrates the data flow and the main components of the tool:
.srcjar archives or individual .java files from disk into memory for processing..srcjar..java files against an optional package allowlist (--packages), and acts as a guardrail by aborting if any disallowed file contains changelogging annotations.@TrackedType and @TrackedField annotations, producing raw metadata (RawType) about what needs to be tracked.@TrackedType classes and parent classes referenced by internal types.TrackedGraph to propagate polymorphism flags from parent classes down to child classes and validate polymorphic consistency.TrackedGraph to identify immutable versus mutable tracked types and fields, propagating mutability across enclosing types, derived types, and field types.android.graphics.Rect, Point, and Insets) when --emit-companion-classes is enabled.CodeChanges to the original source code, ensuring original line numbers are preserved.