Fix issue #2246723: Only one Application object gets onCreate called
Change-Id: I83ba96fe81ad04258099d6f94a667dc7d9dd4fd3
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index daf4090..b116bf8 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -485,7 +485,8 @@
return mResources;
}
- public Application makeApplication(boolean forceDefaultAppClass) {
+ public Application makeApplication(boolean forceDefaultAppClass,
+ Instrumentation instrumentation) {
if (mApplication != null) {
return mApplication;
}
@@ -512,7 +513,21 @@
}
}
mActivityThread.mAllApplications.add(app);
- return mApplication = app;
+ mApplication = app;
+
+ if (instrumentation != null) {
+ try {
+ instrumentation.callApplicationOnCreate(app);
+ } catch (Exception e) {
+ if (!instrumentation.onException(app, e)) {
+ throw new RuntimeException(
+ "Unable to create application " + app.getClass().getName()
+ + ": " + e.toString(), e);
+ }
+ }
+ }
+
+ return app;
}
public void removeContextRegistrations(Context context,
@@ -2378,7 +2393,7 @@
}
try {
- Application app = r.packageInfo.makeApplication(false);
+ Application app = r.packageInfo.makeApplication(false, mInstrumentation);
if (localLOGV) Log.v(TAG, "Performing launch of " + r);
if (localLOGV) Log.v(
@@ -2576,7 +2591,7 @@
}
try {
- Application app = packageInfo.makeApplication(false);
+ Application app = packageInfo.makeApplication(false, mInstrumentation);
if (localLOGV) Log.v(
TAG, "Performing receive of " + data.intent
@@ -2730,7 +2745,7 @@
ApplicationContext context = new ApplicationContext();
context.init(packageInfo, null, this);
- Application app = packageInfo.makeApplication(false);
+ Application app = packageInfo.makeApplication(false, mInstrumentation);
context.setOuterContext(service);
service.attach(context, this, data.info.name, data.token, app,
ActivityManagerNative.getDefault());
@@ -3940,7 +3955,7 @@
// If the app is being launched for full backup or restore, bring it up in
// a restricted environment with the base application class.
- Application app = data.info.makeApplication(data.restrictedBackupMode);
+ Application app = data.info.makeApplication(data.restrictedBackupMode, null);
mInitialApplication = app;
List<ProviderInfo> providers = data.providers;