Make sure to apply latest configuration to resources

When app is transferred from split-screen mode to fullscreen
and the app doesn't handle configuration change, relaunch is
scheduled with non-empty override config corresponding to
fullscreen size. This override config is then used in instance
of DisplayAdjustments and in size/metrics calculations in
corresponding methods of Display class. To obtain correct values
in fullscreen mode override config should be empty.
Configuration change that follows relaunch has correct (empty)
override config, but it is not really applied for resources
because final config matched current activity config.

Bug: 30185335
Change-Id: I95fb69e0c229c2c6b0c1cd79e9d60556de579ae4
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index 3f15a75..2c5f881 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -4627,11 +4627,12 @@
         if ((activity == null) || (activity.mCurrentConfig == null)) {
             shouldChangeConfig = true;
         } else {
-            // If the new config is the same as the config this Activity
-            // is already running with then don't bother calling
-            // onConfigurationChanged
+            // If the new config is the same as the config this Activity is already
+            // running with and the override config also didn't change, then don't
+            // bother calling onConfigurationChanged.
             int diff = activity.mCurrentConfig.diff(newConfig);
-            if (diff != 0) {
+            if (diff != 0 || !mResourcesManager.isSameResourcesOverrideConfig(activityToken,
+                    amOverrideConfig)) {
                 // Always send the task-level config changes. For system-level configuration, if
                 // this activity doesn't handle any of the config changes, then don't bother
                 // calling onConfigurationChanged as we're going to destroy it.
diff --git a/core/java/android/app/ResourcesManager.java b/core/java/android/app/ResourcesManager.java
index c4673a3..9a9f793 100644
--- a/core/java/android/app/ResourcesManager.java
+++ b/core/java/android/app/ResourcesManager.java
@@ -364,6 +364,26 @@
         return null;
     }
 
+    /**
+     * Check if activity resources have same override config as the provided on.
+     * @param activityToken The Activity that resources should be associated with.
+     * @param overrideConfig The override configuration to be checked for equality with.
+     * @return true if activity resources override config matches the provided one or they are both
+     *         null, false otherwise.
+     */
+    boolean isSameResourcesOverrideConfig(@Nullable IBinder activityToken,
+            @Nullable Configuration overrideConfig) {
+        synchronized (this) {
+            final ActivityResources activityResources
+                    = activityToken != null ? mActivityResourceReferences.get(activityToken) : null;
+            if (activityResources == null) {
+                return overrideConfig == null;
+            } else {
+                return Objects.equals(activityResources.overrideConfig, overrideConfig);
+            }
+        }
+    }
+
     private ActivityResources getOrCreateActivityResourcesStructLocked(
             @NonNull IBinder activityToken) {
         ActivityResources activityResources = mActivityResourceReferences.get(activityToken);