diff options
| author | Ryan Mitchell <rtmitchell@google.com> | 2021-05-13 15:46:34 -0700 |
|---|---|---|
| committer | Ryan Mitchell <rtmitchell@google.com> | 2021-05-18 09:07:58 -0700 |
| commit | c54ebba25be71d77a4c0d92dba2f0b32c03a9792 (patch) | |
| tree | 342ae715c0b88c22db4cfd37aae69cae38ac7ddd /core/java/android/appwidget/AppWidgetHostView.java | |
| parent | 969f4ec61b7f6d069726ffcc795d438af7d47f7d (diff) | |
Deprecate Context#createApplicationContext
If an application caches an ApplicationInfo and uses it to call
Context#createApplicationContext, the app will not get the most recent
version of the overlays for that application. To make things worse, the
LoadedApk stored in ActivityThread#mResourcePackages is updated using
the old ApplicationInfo causing further uses of the cached LoadedApk to
return outdated information.
Deprecate Context#createApplicationContext, convert all internal uses
to Context#createPackageContext(String packageName, ...) and log
whenever any one calls Context#createApplicationContext with an
outdated ApplicationInfo to detect debug issues in using old infos.
Bug: 188059515
Test: change wallpaper and observe widgets get reloaded with most
recent overlays
Change-Id: I2aeefa8c0e66264859109975a54c4f73f76ad710
Diffstat (limited to 'core/java/android/appwidget/AppWidgetHostView.java')
| -rw-r--r-- | core/java/android/appwidget/AppWidgetHostView.java | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/core/java/android/appwidget/AppWidgetHostView.java b/core/java/android/appwidget/AppWidgetHostView.java index 152de4496cac..00dfb9ceed73 100644 --- a/core/java/android/appwidget/AppWidgetHostView.java +++ b/core/java/android/appwidget/AppWidgetHostView.java @@ -37,6 +37,7 @@ import android.os.Build; import android.os.Bundle; import android.os.CancellationSignal; import android.os.Parcelable; +import android.os.UserHandle; import android.util.AttributeSet; import android.util.Log; import android.util.Pair; @@ -713,9 +714,10 @@ public class AppWidgetHostView extends FrameLayout { protected Context getRemoteContext() { try { // Return if cloned successfully, otherwise default - Context newContext = mContext.createApplicationContext( - mInfo.providerInfo.applicationInfo, - Context.CONTEXT_RESTRICTED); + final ApplicationInfo info = mInfo.providerInfo.applicationInfo; + Context newContext = mContext.createPackageContextAsUser(info.packageName, + Context.CONTEXT_RESTRICTED, + UserHandle.getUserHandleForUid(info.uid)); if (mColorResources != null) { mColorResources.apply(newContext); } |
