From cb5a80ea57b51fcde117dea253c546dbba9f27f1 Mon Sep 17 00:00:00 2001 From: Paul Hobbs Date: Tue, 29 Jun 2021 19:54:32 +0000 Subject: Revert^2 "Deprecate Context#createApplicationContext" Bug: 192242649 5a41b45a85286200f029b6ac06d004cb32c88dd0 Change-Id: Idcebd68e0079e7e87de04ae25069b3a9ff72093c --- core/java/android/content/Context.java | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'core/java/android/content/Context.java') diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java index c02dcfd3d681..9c60f431b06e 100644 --- a/core/java/android/content/Context.java +++ b/core/java/android/content/Context.java @@ -46,6 +46,7 @@ import android.app.time.TimeManager; import android.compat.annotation.UnsupportedAppUsage; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; +import android.content.pm.PackageManager.ApplicationInfoFlags; import android.content.res.AssetManager; import android.content.res.ColorStateList; import android.content.res.Configuration; @@ -6267,6 +6268,23 @@ public abstract class Context { return this; } + /** + * Similar to {@link #createPackageContextAsUser(String, int, UserHandle)}, but also allows + * specifying the flags used to retrieve the {@link ApplicationInfo} of the package. + * + * @hide + */ + @NonNull + public Context createPackageContextAsUser( + @NonNull String packageName, @CreatePackageOptions int flags, @NonNull UserHandle user, + @ApplicationInfoFlags int packageFlags) + throws PackageManager.NameNotFoundException { + if (Build.IS_ENG) { + throw new IllegalStateException("createPackageContextAsUser not overridden!"); + } + return this; + } + /** * Similar to {@link #createPackageContext(String, int)}, but for the own package with a * different {@link UserHandle}. For example, {@link #getContentResolver()} @@ -6286,10 +6304,18 @@ public abstract class Context { /** * Creates a context given an {@link android.content.pm.ApplicationInfo}. * + * @deprecated use {@link #createPackageContextAsUser(String, int, UserHandle, int)} + * If an application caches an ApplicationInfo and uses it to call this method, + * the app will not get the most recent version of Runtime Resource Overlays for + * that application. To make things worse, the LoadedApk stored in + * {@code ActivityThread#mResourcePackages} is updated using the old ApplicationInfo + * causing further uses of the cached LoadedApk to return outdated information. + * * @hide */ @SuppressWarnings("HiddenAbstractMethod") @UnsupportedAppUsage + @Deprecated public abstract Context createApplicationContext(ApplicationInfo application, @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException; -- cgit v1.2.3