Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e95a12c3 authored by Pat Manning's avatar Pat Manning
Browse files

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

Bug: 260059325
Test: manual
Change-Id: I7f5ea9f4607ea50ffafb7a19f0ae0e62df2dbb14
parent 74229430
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -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:
+9 −9
Original line number Diff line number Diff line
@@ -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();
        }