From eb9e9ec06167b0caa459f2fb3f3fae094bb8d8f7 Mon Sep 17 00:00:00 2001 From: Christopher Tate Date: Tue, 23 Mar 2010 17:14:36 -0700 Subject: [PATCH] Return the right thing from Context.getApplicationContext() Previously, this would always return the app context for the first application ever instantiated in the process. Usually this is fine, since usually there will be one process per application, but in the case of shared-process apps, it causes activities/views to try to access the wrong set of resources, be unable to access their proper derived-class Application objects, etc. Fixes bug #2513901 Change-Id: Ie19f2a86583c5d927db4d84a4262077450e37539 --- core/java/android/app/ActivityThread.java | 6 +++++- core/java/android/app/ContextImpl.java | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index fa6abec6d9b10..a556a32362692 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -278,6 +278,10 @@ public final class ActivityThread { int mClientCount = 0; + Application getApplication() { + return mApplication; + } + public PackageInfo(ActivityThread activityThread, ApplicationInfo aInfo, ActivityThread mainThread, ClassLoader baseLoader, boolean securityViolation, boolean includeCode) { @@ -648,7 +652,7 @@ public final class ActivityThread { } mActivityThread.mAllApplications.add(app); mApplication = app; - + if (instrumentation != null) { try { instrumentation.callApplicationOnCreate(app); diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java index f296f4376a4ff..4c2b36f0a4683 100644 --- a/core/java/android/app/ContextImpl.java +++ b/core/java/android/app/ContextImpl.java @@ -260,7 +260,8 @@ class ContextImpl extends Context { @Override public Context getApplicationContext() { - return mMainThread.getApplication(); + return (mPackageInfo != null) ? + mPackageInfo.getApplication() : mMainThread.getApplication(); } @Override