Skip to content

Commit

Permalink
Force initialization of instrumentationResultPrinter if its null.
Browse files Browse the repository at this point in the history
Currently AJUR has hard coded per-SDK logic of when to initialize  instrumentationResultPrinter.

This commit simplifies the logic to just always attempt initialization
in either newApplication or onCreate. This should make AJUR more resilient
if the application lifecycle callback sequence ever changes, as it is speculated it does when instrumenting the system server itself.

PiperOrigin-RevId: 558162950
  • Loading branch information
brettchabot authored and copybara-androidxtest committed Aug 18, 2023
1 parent 698e592 commit 43798af
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,14 @@ public Application newApplication(ClassLoader cl, String className, Context cont
throws InstantiationException, IllegalAccessException, ClassNotFoundException {
Log.i(LOG_TAG, "newApplication " + className);
if (VERSION.SDK_INT >= 16) {
// install multidex as soon as possible
installMultidex();
}
if (instrumentationResultPrinter == null) {
// Create instrumentationResultPrinter as early as possible to assist with
// exception handling. InstrumentationResultPrinter use ConcurrentLinkedList,
// and as that is desugared (see b/246860430) it cannot be instantiated before
// multidex is loaded.
installMultidex();
instrumentationResultPrinter = new InstrumentationResultPrinter();
}
return super.newApplication(cl, className, context);
Expand All @@ -307,12 +310,13 @@ public void onCreate(Bundle arguments) {
Trace.beginSection("AndroidJUnitRunner#onCreate");
try {
super.onCreate(arguments);
if (VERSION.SDK_INT <= 15) {
if (instrumentationResultPrinter == null) {
// Create instrumentationResultPrinter as early as possible to assist with
// exception handling. InstrumentationResultPrinter use ConcurrentLinkedList,
// and as that is desugared (see b/246860430) it cannot be instantiated before
// multidex is loaded.
// On API level <= 15, #onCreate is called earlier than #newApplication. See
// On API level <= 15, #onCreate is called earlier than #newApplication so it
// can be null, or if the system server itself is being instrumented. See
// MonitoringInstrumentation#onCreate.
instrumentationResultPrinter = new InstrumentationResultPrinter();
}
Expand Down

0 comments on commit 43798af

Please sign in to comment.