From d156c87685c3100b6a1a1443f46d2690874dd75e Mon Sep 17 00:00:00 2001 From: Pierre Barbier de Reuille Date: Fri, 1 Oct 2021 08:27:52 +0000 Subject: [PATCH] Restore the creation of the remote context in sync inflation. This was mistakenly removed in Android S (in ag/13732454) and could cause issues if the top-level layout parameters are defined using resources defined in the AppWidget's package. Also add some safeguard to avoid crashing if the AppWidgetProviderInfo doesn't contain a ProviderInfo (which can happen if it's not created by the system). Fix: 201744899 Test: Existing CTS tests Change-Id: Ibb4f2c26a6258ec2c68a7fd1fafe3e5fe3551109 --- core/java/android/appwidget/AppWidgetHostView.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/java/android/appwidget/AppWidgetHostView.java b/core/java/android/appwidget/AppWidgetHostView.java index 8aa27853b4622..dd147cc26e592 100644 --- a/core/java/android/appwidget/AppWidgetHostView.java +++ b/core/java/android/appwidget/AppWidgetHostView.java @@ -552,6 +552,10 @@ public class AppWidgetHostView extends FrameLayout { inflateAsync(rvToApply); return; } + // Prepare a local reference to the remote Context so we're ready to + // inflate any requested LayoutParams. + mRemoteContext = getRemoteContext(); + int layoutId = rvToApply.getLayoutId(); if (rvToApply.canRecycleView(mView)) { try { @@ -727,6 +731,9 @@ public class AppWidgetHostView extends FrameLayout { } catch (NameNotFoundException e) { Log.e(TAG, "Package name " + mInfo.providerInfo.packageName + " not found"); return mContext; + } catch (NullPointerException e) { + Log.e(TAG, "Error trying to create the remote context.", e); + return mContext; } }