From 8da886f6b446c8446e7fd30a5bc0c5db819d2616 Mon Sep 17 00:00:00 2001 From: Roshan Pius Date: Wed, 4 Dec 2019 06:55:28 -0800 Subject: WifiContext: Override getAssets, getTheme This needs to be in sync with getResources(). The documentation for Context Jclearly states that if you override getResources(), you also need to override getAssets() to be in sync. This fixes the P2p crash seen when loading the layout/style resources. Bug: 145379441 Test: Manually triggered the p2p crash (by calling notifyInvitationSent on p2p bootup) and verified it no longer crashes with the fix. Change-Id: I989725a824a4703331e54bc06da08113e63da774 --- .../java/com/android/server/wifi/WifiContext.java | 49 +++++++++++++++++++--- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/service/java/com/android/server/wifi/WifiContext.java b/service/java/com/android/server/wifi/WifiContext.java index 5ac6f208d..0a67a1e15 100644 --- a/service/java/com/android/server/wifi/WifiContext.java +++ b/service/java/com/android/server/wifi/WifiContext.java @@ -20,6 +20,7 @@ import android.annotation.NonNull; import android.content.Context; import android.content.ContextWrapper; import android.content.pm.PackageManager; +import android.content.res.AssetManager; import android.content.res.Resources; import android.util.Log; @@ -32,26 +33,62 @@ public class WifiContext extends ContextWrapper { private static final String WIFI_OVERLAY_APK_PKG_NAME = "com.android.wifi.resources"; // Cached resources from the resources APK. + private AssetManager mWifiAssetsFromApk; private Resources mWifiResourcesFromApk; + private Resources.Theme mWifiThemeFromApk; public WifiContext(@NonNull Context contextBase) { super(contextBase); } + private Context getResourcesApkContext() { + try { + return createPackageContext(WIFI_OVERLAY_APK_PKG_NAME, 0); + } catch (PackageManager.NameNotFoundException e) { + Log.wtf(TAG, "Failed to load resources", e); + } + return null; + } + + /** + * Retrieve assets held in the wifi resources APK. + */ + @Override + public AssetManager getAssets() { + if (mWifiAssetsFromApk == null) { + Context resourcesApkContext = getResourcesApkContext(); + if (resourcesApkContext != null) { + mWifiAssetsFromApk = resourcesApkContext.getAssets(); + } + } + return mWifiAssetsFromApk; + } + /** * Retrieve resources held in the wifi resources APK. */ @Override public Resources getResources() { if (mWifiResourcesFromApk == null) { - try { - Context overlayAppContext = - createPackageContext(WIFI_OVERLAY_APK_PKG_NAME, 0); - mWifiResourcesFromApk = overlayAppContext.getResources(); - } catch (PackageManager.NameNotFoundException e) { - Log.wtf(TAG, "Failed to load resources", e); + Context resourcesApkContext = getResourcesApkContext(); + if (resourcesApkContext != null) { + mWifiResourcesFromApk = resourcesApkContext.getResources(); } } return mWifiResourcesFromApk; } + + /** + * Retrieve theme held in the wifi resources APK. + */ + @Override + public Resources.Theme getTheme() { + if (mWifiThemeFromApk == null) { + Context resourcesApkContext = getResourcesApkContext(); + if (resourcesApkContext != null) { + mWifiThemeFromApk = resourcesApkContext.getTheme(); + } + } + return mWifiThemeFromApk; + } } -- cgit v1.2.3