From 7d1fdb7389e121fabefaf23510a99cf585c27f0c Mon Sep 17 00:00:00 2001 From: Elliot Sisteron Date: Thu, 18 May 2023 11:59:01 +0000 Subject: Fix crash when posting notification on HSUM. Bug: 283100177 Test: atest SafetyCenterNotificationTest (on hsum) Relnote: Fix crash in headless system user mode Change-Id: Iec7e6bb36d00b23bbf8909058870b7f61eb7b2ec --- .../resources/SafetyCenterResourcesContext.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'SafetyCenter') diff --git a/SafetyCenter/ResourcesLib/java/com/android/safetycenter/resources/SafetyCenterResourcesContext.java b/SafetyCenter/ResourcesLib/java/com/android/safetycenter/resources/SafetyCenterResourcesContext.java index 5417e7b89..9a77296e2 100644 --- a/SafetyCenter/ResourcesLib/java/com/android/safetycenter/resources/SafetyCenterResourcesContext.java +++ b/SafetyCenter/ResourcesLib/java/com/android/safetycenter/resources/SafetyCenterResourcesContext.java @@ -123,6 +123,21 @@ public class SafetyCenterResourcesContext extends ContextWrapper { contextBase, /* shouldFallbackIfNamedResourceNotFound */ false); } + /** + * Initializes the {@link Context}'s {@link AssetManager}, {@link Resources} and {@link + * Resources.Theme}. + * + *

This call is optional as this can also be lazily instantiated. This is useful to ensure + * that resources are loaded prior to interacting with the {@link SafetyCenterResourcesContext}, + * as this code needs to run for the same user as the provided base {@link Context}; which may + * not be the case with a binder call. + */ + public void init() { + mAssetsFromApk = getAssets(); + mResourcesFromApk = getResources(); + mThemeFromApk = getTheme(); + } + /** Get the package name of the Safety Center resources APK. */ @VisibleForTesting @Nullable -- cgit v1.2.3