Get home rotation default value from DisplayController Info in case DeviceProfile is not updated.

Bug: 260059325
Test: manual
Change-Id: I7f5ea9f4607ea50ffafb7a19f0ae0e62df2dbb14
diff --git a/src/com/android/launcher3/settings/SettingsActivity.java b/src/com/android/launcher3/settings/SettingsActivity.java
index 4cb4348..3e2d051 100644
--- a/src/com/android/launcher3/settings/SettingsActivity.java
+++ b/src/com/android/launcher3/settings/SettingsActivity.java
@@ -53,6 +53,7 @@
 import com.android.launcher3.model.WidgetsModel;
 import com.android.launcher3.states.RotationHelper;
 import com.android.launcher3.uioverrides.plugins.PluginManagerWrapper;
+import com.android.launcher3.util.DisplayController;
 
 import java.util.Collections;
 import java.util.List;
@@ -267,15 +268,14 @@
                     return !WidgetsModel.GO_DISABLE_NOTIFICATION_DOTS;
 
                 case ALLOW_ROTATION_PREFERENCE_KEY:
-                    DeviceProfile deviceProfile = InvariantDeviceProfile.INSTANCE.get(
-                            getContext()).getDeviceProfile(getContext());
-                    if (deviceProfile.isTablet) {
+                    DisplayController.Info info = InvariantDeviceProfile.INSTANCE.get(
+                            getContext()).getDeviceProfile(getContext()).getDisplayInfo();
+                    if (info.isTablet(info.realBounds)) {
                         // Launcher supports rotation by default. No need to show this setting.
                         return false;
                     }
                     // Initialize the UI once
-                    preference.setDefaultValue(
-                            RotationHelper.getAllowRotationDefaultValue(deviceProfile));
+                    preference.setDefaultValue(RotationHelper.getAllowRotationDefaultValue(info));
                     return true;
 
                 case FLAGS_PREFERENCE_KEY:
diff --git a/src/com/android/launcher3/states/RotationHelper.java b/src/com/android/launcher3/states/RotationHelper.java
index 642bdcd..e5b4eba 100644
--- a/src/com/android/launcher3/states/RotationHelper.java
+++ b/src/com/android/launcher3/states/RotationHelper.java
@@ -35,7 +35,6 @@
 import androidx.annotation.WorkerThread;
 
 import com.android.launcher3.BaseActivity;
-import com.android.launcher3.DeviceProfile;
 import com.android.launcher3.LauncherPrefs;
 import com.android.launcher3.util.DisplayController;
 
@@ -50,11 +49,11 @@
     /**
      * Returns the default value of {@link #ALLOW_ROTATION_PREFERENCE_KEY} preference.
      */
-    public static boolean getAllowRotationDefaultValue(DeviceProfile deviceProfile) {
+    public static boolean getAllowRotationDefaultValue(DisplayController.Info info) {
         // If the device's pixel density was scaled (usually via settings for A11y), use the
         // original dimensions to determine if rotation is allowed of not.
-        float originalSmallestWidth = dpiFromPx(
-                Math.min(deviceProfile.widthPx, deviceProfile.heightPx), DENSITY_DEVICE_STABLE);
+        float originalSmallestWidth = dpiFromPx(Math.min(info.currentSize.x, info.currentSize.y),
+                DENSITY_DEVICE_STABLE);
         return originalSmallestWidth >= MIN_TABLET_WIDTH;
     }
 
@@ -99,7 +98,8 @@
                 new Handler(UI_HELPER_EXECUTOR.getLooper(), this::setOrientationAsync);
     }
 
-    private void setIgnoreAutoRotateSettings(boolean ignoreAutoRotateSettings) {
+    private void setIgnoreAutoRotateSettings(boolean ignoreAutoRotateSettings,
+            DisplayController.Info info) {
         // On large devices we do not handle auto-rotate differently.
         mIgnoreAutoRotateSettings = ignoreAutoRotateSettings;
         if (!mIgnoreAutoRotateSettings) {
@@ -108,7 +108,7 @@
                 mSharedPrefs.registerOnSharedPreferenceChangeListener(this);
             }
             mHomeRotationEnabled = mSharedPrefs.getBoolean(ALLOW_ROTATION_PREFERENCE_KEY,
-                    getAllowRotationDefaultValue(mActivity.getDeviceProfile()));
+                    getAllowRotationDefaultValue(info));
         } else {
             if (mSharedPrefs != null) {
                 mSharedPrefs.unregisterOnSharedPreferenceChangeListener(this);
@@ -122,7 +122,7 @@
         if (mDestroyed || mIgnoreAutoRotateSettings) return;
         boolean wasRotationEnabled = mHomeRotationEnabled;
         mHomeRotationEnabled = mSharedPrefs.getBoolean(ALLOW_ROTATION_PREFERENCE_KEY,
-                getAllowRotationDefaultValue(mActivity.getDeviceProfile()));
+                getAllowRotationDefaultValue(mActivity.getDeviceProfile().getDisplayInfo()));
         if (mHomeRotationEnabled != wasRotationEnabled) {
             notifyChange();
         }
@@ -132,7 +132,7 @@
     public void onDisplayInfoChanged(Context context, DisplayController.Info info, int flags) {
         boolean ignoreAutoRotateSettings = info.isTablet(info.realBounds);
         if (mIgnoreAutoRotateSettings != ignoreAutoRotateSettings) {
-            setIgnoreAutoRotateSettings(ignoreAutoRotateSettings);
+            setIgnoreAutoRotateSettings(ignoreAutoRotateSettings, info);
             notifyChange();
         }
     }
@@ -169,7 +169,7 @@
             mInitialized = true;
             DisplayController displayController = DisplayController.INSTANCE.get(mActivity);
             DisplayController.Info info = displayController.getInfo();
-            setIgnoreAutoRotateSettings(info.isTablet(info.realBounds));
+            setIgnoreAutoRotateSettings(info.isTablet(info.realBounds), info);
             displayController.addChangeListener(this);
             notifyChange();
         }