Detect potential WindowConfiguration change at onApplyWindowInsets

- Invoke onConfiguration when receiving inset changes
- In Laucnher/RecentsActivity onConfiguration, additionally detect for windowConfiguration's rotation change; if Configuration stays the same, it'll be ignored.

Bug: 240730723
Test: manual on 90/180 degree rotation in Launcher and RecentsActivity
Change-Id: I7087878af847d62e1c715a4f52a18818d1a6c258
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 5ee9aa8..03ff146 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -615,14 +615,18 @@
     }
 
     @Override
-    public void onConfigurationChanged(Configuration newConfig) {
-        int diff = newConfig.diff(mOldConfig);
-        if ((diff & (CONFIG_ORIENTATION | CONFIG_SCREEN_SIZE)) != 0) {
+    public void handleConfigurationChanged(Configuration newConfig) {
+        if (compareConfiguration(mOldConfig, newConfig)) {
             onIdpChanged(false);
         }
 
         mOldConfig.setTo(newConfig);
-        super.onConfigurationChanged(newConfig);
+        super.handleConfigurationChanged(newConfig);
+    }
+
+    protected boolean compareConfiguration(Configuration oldConfig, Configuration newConfig) {
+        int diff = newConfig.diff(oldConfig);
+        return (diff & (CONFIG_ORIENTATION | CONFIG_SCREEN_SIZE)) != 0;
     }
 
     /**
diff --git a/src/com/android/launcher3/LauncherRootView.java b/src/com/android/launcher3/LauncherRootView.java
index a5c5c02..1592154 100644
--- a/src/com/android/launcher3/LauncherRootView.java
+++ b/src/com/android/launcher3/LauncherRootView.java
@@ -55,6 +55,8 @@
 
     @Override
     public WindowInsets onApplyWindowInsets(WindowInsets insets) {
+        mActivity.handleConfigurationChanged(mActivity.getResources().getConfiguration());
+
         insets = WindowManagerProxy.INSTANCE.get(getContext())
                 .normalizeWindowInsets(getContext(), insets, mTempRect);
         handleSystemWindowInsets(mTempRect);
diff --git a/src/com/android/launcher3/statemanager/StatefulActivity.java b/src/com/android/launcher3/statemanager/StatefulActivity.java
index 2158dea..eea9091 100644
--- a/src/com/android/launcher3/statemanager/StatefulActivity.java
+++ b/src/com/android/launcher3/statemanager/StatefulActivity.java
@@ -18,6 +18,7 @@
 import static com.android.launcher3.LauncherState.FLAG_CLOSE_POPUPS;
 import static com.android.launcher3.LauncherState.FLAG_NON_INTERACTIVE;
 
+import android.content.res.Configuration;
 import android.os.Handler;
 import android.view.LayoutInflater;
 import android.view.View;
@@ -186,4 +187,16 @@
     public void runOnBindToTouchInteractionService(Runnable r) {
         r.run();
     }
+
+    @Override
+    public void onConfigurationChanged(Configuration newConfig) {
+        handleConfigurationChanged(newConfig);
+        super.onConfigurationChanged(newConfig);
+    }
+
+    /**
+     * Handles configuration change when system calls {@link #onConfigurationChanged}, or on other
+     * situations that configuration might change.
+     */
+    public void handleConfigurationChanged(Configuration newConfig) {}
 }