Commit 167a0f68 authored by Andrew Grieve's avatar Andrew Grieve Committed by Commit Bot

Android: Fix (harmless) exception in logcat on start-up

Message looked like:
Uninitialized ActivityThread, likely app-created Instrumentation, disabling AppComponentFactory

Bug: 1025357
Change-Id: I68fe01719f4fb4624d742cb46b54ea9525500d56
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2122233
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Commit-Queue: Peter Wen <wnwen@chromium.org>
Auto-Submit: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: default avatarPeter Wen <wnwen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#753645}
parent 8a3cdc59
...@@ -130,8 +130,9 @@ public final class BootstrapApplication extends Application { ...@@ -130,8 +130,9 @@ public final class BootstrapApplication extends Application {
// Even when instrumentation is not enabled, ActivityThread uses a default // Even when instrumentation is not enabled, ActivityThread uses a default
// Instrumentation instance internally. We hook it here in order to hook into the // Instrumentation instance internally. We hook it here in order to hook into the
// call to Instrumentation.onCreate(). // call to Instrumentation.onCreate().
Reflect.setField(mActivityThread, "mInstrumentation", BootstrapInstrumentation bootstrapInstrumentation = new BootstrapInstrumentation(this);
new BootstrapInstrumentation(this)); populateInstrumenationFields(bootstrapInstrumentation);
Reflect.setField(mActivityThread, "mInstrumentation", bootstrapInstrumentation);
// attachBaseContext() is called from ActivityThread#handleBindApplication() and // attachBaseContext() is called from ActivityThread#handleBindApplication() and
// Application#mApplication is changed right after we return. Thus, we cannot swap // Application#mApplication is changed right after we return. Thus, we cannot swap
...@@ -188,14 +189,22 @@ public final class BootstrapApplication extends Application { ...@@ -188,14 +189,22 @@ public final class BootstrapApplication extends Application {
Log.i(TAG, "Instantiating instrumentation " + realInstrumentationName); Log.i(TAG, "Instantiating instrumentation " + realInstrumentationName);
Instrumentation ret = Instrumentation ret =
(Instrumentation) Reflect.newInstance(Class.forName(realInstrumentationName)); (Instrumentation) Reflect.newInstance(Class.forName(realInstrumentationName));
populateInstrumenationFields(ret);
return ret;
}
/**
* Sets important fields on a newly created Instrumentation object by copying them from the
* original Instrumentation instance.
*/
private void populateInstrumenationFields(Instrumentation target)
throws ReflectiveOperationException {
// Initialize the fields that are set by Instrumentation.init(). // Initialize the fields that are set by Instrumentation.init().
String[] initFields = {"mAppContext", "mComponent", "mInstrContext", "mMessageQueue", String[] initFields = {"mAppContext", "mComponent", "mInstrContext", "mMessageQueue",
"mThread", "mUiAutomationConnection", "mWatcher"}; "mThread", "mUiAutomationConnection", "mWatcher"};
for (String fieldName : initFields) { for (String fieldName : initFields) {
Reflect.setField(ret, fieldName, Reflect.getField(mOrigInstrumentation, fieldName)); Reflect.setField(target, fieldName, Reflect.getField(mOrigInstrumentation, fieldName));
} }
return ret;
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment