From 2998307cd6b49a35fdb7382260a53a315c6413bd Mon Sep 17 00:00:00 2001 From: Alex Chau Date: Fri, 19 Nov 2021 15:14:20 +0000 Subject: [PATCH] Use only current density to check isTablet - Removed DeviceProfile.allowRotation and use DeviceProfile.isTablet instead, which only uses current density to calculate its value - Reverted default allow_rotation preference handling to before ag/14234761 Fix: 203817448 Test: isTablet is set correctly in different screen sizes Change-Id: Ic6c8dfc774e7787f62d489ad27720a7644c1e8c7 --- .../quickstep/util/RecentsOrientedState.java | 2 +- src/com/android/launcher3/DeviceProfile.java | 12 +-------- .../launcher3/settings/SettingsActivity.java | 6 +++-- .../launcher3/states/RotationHelper.java | 26 ++++++++++++++----- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/quickstep/src/com/android/quickstep/util/RecentsOrientedState.java b/quickstep/src/com/android/quickstep/util/RecentsOrientedState.java index 9c6fd3dd99..8ccab71f63 100644 --- a/quickstep/src/com/android/quickstep/util/RecentsOrientedState.java +++ b/quickstep/src/com/android/quickstep/util/RecentsOrientedState.java @@ -162,7 +162,7 @@ public class RecentsOrientedState implements */ public void setDeviceProfile(DeviceProfile deviceProfile) { boolean oldMultipleOrientationsSupported = isMultipleOrientationSupportedByDevice(); - setFlag(FLAG_MULTIPLE_ORIENTATION_SUPPORTED_BY_DENSITY, !deviceProfile.allowRotation); + setFlag(FLAG_MULTIPLE_ORIENTATION_SUPPORTED_BY_DENSITY, !deviceProfile.isTablet); if (mListenersInitialized) { boolean newMultipleOrientationsSupported = isMultipleOrientationSupportedByDevice(); // If isMultipleOrientationSupportedByDevice is changed, init or destroy listeners diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java index e64ea90160..f2836ca6ca 100644 --- a/src/com/android/launcher3/DeviceProfile.java +++ b/src/com/android/launcher3/DeviceProfile.java @@ -16,13 +16,10 @@ package com.android.launcher3; -import static android.util.DisplayMetrics.DENSITY_DEVICE_STABLE; - import static com.android.launcher3.ResourceUtils.pxFromDp; import static com.android.launcher3.Utilities.dpiFromPx; import static com.android.launcher3.Utilities.pxFromSp; import static com.android.launcher3.folder.ClippedFolderIconLayoutRule.ICON_OVERLAP_FACTOR; -import static com.android.launcher3.util.WindowManagerCompat.MIN_TABLET_WIDTH; import android.annotation.SuppressLint; import android.content.Context; @@ -64,7 +61,6 @@ public class DeviceProfile { public final boolean isPhone; public final boolean transposeLayoutWithOrientation; public final boolean isTwoPanels; - public final boolean allowRotation; // Device properties in current orientation public final boolean isLandscape; @@ -244,12 +240,7 @@ public class DeviceProfile { availableHeightPx = windowBounds.availableSize.y; mInfo = 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(widthPx, heightPx), DENSITY_DEVICE_STABLE); - allowRotation = originalSmallestWidth >= MIN_TABLET_WIDTH; - // Tablet UI does not support emulated landscape. - isTablet = allowRotation && info.isTablet(windowBounds); + isTablet = info.isTablet(windowBounds); isPhone = !isTablet; isTwoPanels = isTablet && useTwoPanels; @@ -1031,7 +1022,6 @@ public class DeviceProfile { writer.println(prefix + "DeviceProfile:"); writer.println(prefix + "\t1 dp = " + mMetrics.density + " px"); - writer.println(prefix + "\tallowRotation:" + allowRotation); writer.println(prefix + "\tisTablet:" + isTablet); writer.println(prefix + "\tisPhone:" + isPhone); writer.println(prefix + "\ttransposeLayoutWithOrientation:" diff --git a/src/com/android/launcher3/settings/SettingsActivity.java b/src/com/android/launcher3/settings/SettingsActivity.java index f348a339fd..0c39632708 100644 --- a/src/com/android/launcher3/settings/SettingsActivity.java +++ b/src/com/android/launcher3/settings/SettingsActivity.java @@ -49,6 +49,7 @@ import com.android.launcher3.R; import com.android.launcher3.Utilities; 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 java.util.Collections; @@ -253,12 +254,13 @@ public class SettingsActivity extends FragmentActivity case ALLOW_ROTATION_PREFERENCE_KEY: DeviceProfile deviceProfile = InvariantDeviceProfile.INSTANCE.get( getContext()).getDeviceProfile(getContext()); - if (deviceProfile.allowRotation) { + if (deviceProfile.isTablet) { // Launcher supports rotation by default. No need to show this setting. return false; } // Initialize the UI once - preference.setDefaultValue(false); + preference.setDefaultValue( + RotationHelper.getAllowRotationDefaultValue(deviceProfile)); 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 87871b11db..867fd990d0 100644 --- a/src/com/android/launcher3/states/RotationHelper.java +++ b/src/com/android/launcher3/states/RotationHelper.java @@ -18,6 +18,10 @@ package com.android.launcher3.states; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LOCKED; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_NOSENSOR; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; +import static android.util.DisplayMetrics.DENSITY_DEVICE_STABLE; + +import static com.android.launcher3.Utilities.dpiFromPx; +import static com.android.launcher3.util.WindowManagerCompat.MIN_TABLET_WIDTH; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; @@ -25,7 +29,6 @@ import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import com.android.launcher3.BaseActivity; import com.android.launcher3.DeviceProfile; import com.android.launcher3.Utilities; -import com.android.launcher3.util.ActivityTracker; import com.android.launcher3.util.UiThreadHelper; /** @@ -38,6 +41,17 @@ public class RotationHelper implements OnSharedPreferenceChangeListener, public static final String ALLOW_ROTATION_PREFERENCE_KEY = "pref_allowRotation"; + /** + * Returns the default value of {@link #ALLOW_ROTATION_PREFERENCE_KEY} preference. + */ + public static boolean getAllowRotationDefaultValue(DeviceProfile deviceProfile) { + // 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); + return originalSmallestWidth >= MIN_TABLET_WIDTH; + } + public static final int REQUEST_NONE = 0; public static final int REQUEST_ROTATE = 1; public static final int REQUEST_LOCK = 2; @@ -51,7 +65,7 @@ public class RotationHelper implements OnSharedPreferenceChangeListener, /** * Rotation request made by - * {@link ActivityTracker.SchedulerCallback}. + * {@link com.android.launcher3.util.ActivityTracker.SchedulerCallback}. * This supersedes any other request. */ private int mStateHandlerRequest = REQUEST_NONE; @@ -84,7 +98,7 @@ public class RotationHelper implements OnSharedPreferenceChangeListener, mSharedPrefs.registerOnSharedPreferenceChangeListener(this); } mHomeRotationEnabled = mSharedPrefs.getBoolean(ALLOW_ROTATION_PREFERENCE_KEY, - mActivity.getDeviceProfile().allowRotation); + getAllowRotationDefaultValue(mActivity.getDeviceProfile())); } else { if (mSharedPrefs != null) { mSharedPrefs.unregisterOnSharedPreferenceChangeListener(this); @@ -98,7 +112,7 @@ public class RotationHelper implements OnSharedPreferenceChangeListener, if (mDestroyed) return; boolean wasRotationEnabled = mHomeRotationEnabled; mHomeRotationEnabled = mSharedPrefs.getBoolean(ALLOW_ROTATION_PREFERENCE_KEY, - mActivity.getDeviceProfile().allowRotation); + getAllowRotationDefaultValue(mActivity.getDeviceProfile())); if (mHomeRotationEnabled != wasRotationEnabled) { notifyChange(); } @@ -106,7 +120,7 @@ public class RotationHelper implements OnSharedPreferenceChangeListener, @Override public void onDeviceProfileChanged(DeviceProfile dp) { - boolean ignoreAutoRotateSettings = dp.allowRotation; + boolean ignoreAutoRotateSettings = dp.isTablet; if (mIgnoreAutoRotateSettings != ignoreAutoRotateSettings) { setIgnoreAutoRotateSettings(ignoreAutoRotateSettings); notifyChange(); @@ -143,7 +157,7 @@ public class RotationHelper implements OnSharedPreferenceChangeListener, public void initialize() { if (!mInitialized) { mInitialized = true; - setIgnoreAutoRotateSettings(mActivity.getDeviceProfile().allowRotation); + setIgnoreAutoRotateSettings(mActivity.getDeviceProfile().isTablet); mActivity.addOnDeviceProfileChangeListener(this); notifyChange(); }