diff options
Diffstat (limited to 'android/app/Instrumentation.java')
-rw-r--r-- | android/app/Instrumentation.java | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/android/app/Instrumentation.java b/android/app/Instrumentation.java index d49e11f4..b469de56 100644 --- a/android/app/Instrumentation.java +++ b/android/app/Instrumentation.java @@ -1114,7 +1114,10 @@ public class Instrumentation { public Application newApplication(ClassLoader cl, String className, Context context) throws InstantiationException, IllegalAccessException, ClassNotFoundException { - return newApplication(cl.loadClass(className), context); + Application app = getFactory(context.getPackageName()) + .instantiateApplication(cl, className); + app.attach(context); + return app; } /** @@ -1201,7 +1204,20 @@ public class Instrumentation { Intent intent) throws InstantiationException, IllegalAccessException, ClassNotFoundException { - return (Activity)cl.loadClass(className).newInstance(); + String pkg = intent.getComponent().getPackageName(); + return getFactory(pkg).instantiateActivity(cl, className, intent); + } + + private AppComponentFactory getFactory(String pkg) { + if (mThread == null) { + Log.e(TAG, "Uninitialized ActivityThread, likely app-created Instrumentation," + + " disabling AppComponentFactory", new Throwable()); + return AppComponentFactory.DEFAULT; + } + LoadedApk loadedApk = mThread.peekLoadedApk(pkg, true); + // This is in the case of starting up "android". + if (loadedApk == null) loadedApk = mThread.getSystemContext().mLoadedApk; + return loadedApk.getAppFactory(); } private void prePerformCreate(Activity activity) { @@ -1950,6 +1966,14 @@ public class Instrumentation { mUiAutomationConnection = uiAutomationConnection; } + /** + * Only sets the ActivityThread up, keeps everything else null because app is not being + * instrumented. + */ + final void basicInit(ActivityThread thread) { + mThread = thread; + } + /** @hide */ public static void checkStartActivityResult(int res, Object intent) { if (!ActivityManager.isStartResultFatalError(res)) { |