From e95a12c329738aee3eb0b45eddd187d534115b3e Mon Sep 17 00:00:00 2001 From: Pat Manning Date: Tue, 13 Dec 2022 15:19:51 +0000 Subject: [PATCH] Get home rotation default value from DisplayController Info in case DeviceProfile is not updated. Bug: 260059325 Test: manual Change-Id: I7f5ea9f4607ea50ffafb7a19f0ae0e62df2dbb14 --- .../launcher3/settings/SettingsActivity.java | 10 +++++----- .../launcher3/states/RotationHelper.java | 18 +++++++++--------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/com/android/launcher3/settings/SettingsActivity.java b/src/com/android/launcher3/settings/SettingsActivity.java index 4cb4348a5e..3e2d051a0a 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.config.FeatureFlags; 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 @@ public class SettingsActivity extends FragmentActivity 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 642bdcdbb8..e5b4ebae1d 100644 --- a/src/com/android/launcher3/states/RotationHelper.java +++ b/src/com/android/launcher3/states/RotationHelper.java @@ -35,7 +35,6 @@ import androidx.annotation.Nullable; 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 @@ public class RotationHelper implements OnSharedPreferenceChangeListener, /** * 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 @@ public class RotationHelper implements OnSharedPreferenceChangeListener, 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 @@ public class RotationHelper implements OnSharedPreferenceChangeListener, 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 @@ public class RotationHelper implements OnSharedPreferenceChangeListener, 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 class RotationHelper implements OnSharedPreferenceChangeListener, 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 @@ public class RotationHelper implements OnSharedPreferenceChangeListener, 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(); }