Merge "Make sure system UI context has the same LoadedApk as system context" into oc-dev
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index 3167ba7..5022d7d 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -2199,7 +2199,7 @@
     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 75f9d67..6cc8a14 100644
--- a/core/java/android/app/ContextImpl.java
+++ b/core/java/android/app/ContextImpl.java
@@ -2220,11 +2220,12 @@
 
     /**
      * 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;