fix recursion for config change

- update mTempConfig from mCurConfig first to decide if
  config is changed or not. This fixes recursion of putting
  new config again from reconfigureDisplay
- ignore setNewConfiguration if there is no change in configuration
  This fixes another recursion due to config change -> app restart
  loop

bug: 28381048

Change-Id: I4c2e6072b269baf9fa11d4b8073f0800c0e0d28d
diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java
index cf415ff..ac5df6a 100644
--- a/services/core/java/com/android/server/wm/WindowManagerService.java
+++ b/services/core/java/com/android/server/wm/WindowManagerService.java
@@ -3625,8 +3625,7 @@
             // disregarding font scale, which should remain set to
             // the value of the previous configuration.
             mTempConfiguration.setToDefaults();
-            mTempConfiguration.fontScale = currentConfig.fontScale;
-            mTempConfiguration.uiMode = currentConfig.uiMode;
+            mTempConfiguration.updateFrom(currentConfig);
             computeScreenConfigurationLocked(mTempConfiguration);
             if (currentConfig.diff(mTempConfiguration) != 0) {
                 mWaitingForConfig = true;
@@ -3689,11 +3688,15 @@
         }
 
         synchronized(mWindowMap) {
-            mCurConfiguration = new Configuration(config);
             if (mWaitingForConfig) {
                 mWaitingForConfig = false;
                 mLastFinishedFreezeSource = "new-config";
             }
+            boolean configChanged = mCurConfiguration.diff(config) != 0;
+            if (!configChanged) {
+                return null;
+            }
+            mCurConfiguration = new Configuration(config);
             return onConfigurationChanged();
         }
     }
@@ -8877,8 +8880,7 @@
 
         boolean configChanged = updateOrientationFromAppTokensLocked(false);
         mTempConfiguration.setToDefaults();
-        mTempConfiguration.fontScale = mCurConfiguration.fontScale;
-        mTempConfiguration.uiMode = mCurConfiguration.uiMode;
+        mTempConfiguration.updateFrom(mCurConfiguration);
         computeScreenConfigurationLocked(mTempConfiguration);
         configChanged |= mCurConfiguration.diff(mTempConfiguration) != 0;