summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2019-12-04 06:55:28 -0800
committerRoshan Pius <rpius@google.com>2019-12-04 12:54:48 -0800
commit8da886f6b446c8446e7fd30a5bc0c5db819d2616 (patch)
tree4d84611260dfb1f892de23a54c0e5e774af93321
parent6f033e3c20788e7aa82eb87a52c7b2ac645de34d (diff)
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
-rw-r--r--service/java/com/android/server/wifi/WifiContext.java49
1 files 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;
+ }
}