From 6f1a91713499db1f3d5e825c0f12827dd1870459 Mon Sep 17 00:00:00 2001 From: Adam Lesinski Date: Mon, 10 Apr 2017 16:35:19 -0700 Subject: [PATCH] Make sure system UI context has the same LoadedApk as system context When the system Application object is created, it should be shared by both system and system UI context. Bug: 37111478 Test: - Open settings Test: - adb shell am crash com.android.settings Test: - with crash dialog open, press volume keys Test: - observe no crash Change-Id: I2b4656680d25fe61fee69c01ee10522aac4e2942 --- core/java/android/app/ActivityThread.java | 2 +- core/java/android/app/ContextImpl.java | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index 182982a638f1f..9f947db69279f 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -2199,7 +2199,7 @@ public final class ActivityThread { public ContextImpl getSystemUiContext() { synchronized (this) { if (mSystemUiContext == null) { - mSystemUiContext = ContextImpl.createSystemUiContext(this); + mSystemUiContext = ContextImpl.createSystemUiContext(getSystemContext()); } return mSystemUiContext; } diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java index 75f9d671fbad7..6cc8a14ea2f98 100644 --- a/core/java/android/app/ContextImpl.java +++ b/core/java/android/app/ContextImpl.java @@ -2220,11 +2220,12 @@ class ContextImpl extends Context { /** * System Context to be used for UI. This Context has resources that can be themed. + * Make sure that the created system UI context shares the same LoadedApk as the system context. */ - static ContextImpl createSystemUiContext(ActivityThread mainThread) { - LoadedApk packageInfo = new LoadedApk(mainThread); - ContextImpl context = new ContextImpl(null, mainThread, packageInfo, null, null, null, 0, - null); + static ContextImpl createSystemUiContext(ContextImpl systemContext) { + final LoadedApk packageInfo = systemContext.mPackageInfo; + ContextImpl context = new ContextImpl(null, systemContext.mMainThread, packageInfo, null, + null, null, 0, null); context.setResources(createResources(null, packageInfo, null, Display.DEFAULT_DISPLAY, null, packageInfo.getCompatibilityInfo())); return context;