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 {
// Even when instrumentation is not enabled, ActivityThread uses a default
// Instrumentation instance internally. We hook it here in order to hook into the
// call to Instrumentation.onCreate().
Reflect.setField(mActivityThread, "mInstrumentation",
new BootstrapInstrumentation(this));
BootstrapInstrumentation bootstrapInstrumentation = new BootstrapInstrumentation(this);
populateInstrumenationFields(bootstrapInstrumentation);
Reflect.setField(mActivityThread, "mInstrumentation", bootstrapInstrumentation);
// attachBaseContext() is called from ActivityThread#handleBindApplication() and
// Application#mApplication is changed right after we return. Thus, we cannot swap
......@@ -188,14 +189,22 @@ public final class BootstrapApplication extends Application {
Log.i(TAG, "Instantiating instrumentation " + realInstrumentationName);
Instrumentation ret =
(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().
String[] initFields = {"mAppContext", "mComponent", "mInstrContext", "mMessageQueue",
"mThread", "mUiAutomationConnection", "mWatcher"};
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