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

Commit 94541b99 authored by Vinit Nayak's avatar Vinit Nayak
Browse files

Rotate overview only if system rotation allowed

Don't rotate overview if all of launcher can
be rotated.

Fixes: 154243745, 154299710
Test: Toggled system rotation while overview
was showing. Also toggled home rotation to
ensure no intermediate overview rotation
animation.

Change-Id: I49acf2dafb84e7f05c46f8908ba9ffdd43f1d1e7
parent 8699bf56
Loading
Loading
Loading
Loading
+19 −8
Original line number Diff line number Diff line
@@ -285,6 +285,9 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
        }
    };

    private final RecentsOrientedState.SystemRotationChangeListener mSystemRotationChangeListener =
            enabled -> toggleOrientationEventListener();

    private final PinnedStackAnimationListener mIPinnedStackAnimationListener =
            new PinnedStackAnimationListener();

@@ -487,6 +490,7 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
                mIPinnedStackAnimationListener);
        setActionsView();
        mOrientationState.init();
        mOrientationState.addSystemRotationChangeListener(mSystemRotationChangeListener);
    }

    @Override
@@ -501,6 +505,7 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
        mIdp.removeOnChangeListener(this);
        SystemUiProxy.INSTANCE.get(getContext()).setPinnedStackAnimationListener(null);
        mIPinnedStackAnimationListener.setActivity(null);
        mOrientationState.removeSystemRotationChangeListener(mSystemRotationChangeListener);
        mOrientationState.destroy();
    }

@@ -555,13 +560,6 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
    }

    public void setOverviewStateEnabled(boolean enabled) {
        if (canEnableOverviewRotationAnimation()) {
            if (enabled) {
                mOrientationListener.enable();
            } else {
                mOrientationListener.disable();
            }
        }
        mOverviewStateEnabled = enabled;
        updateTaskStackListenerState();
        if (!enabled) {
@@ -569,13 +567,26 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
            // its thumbnail
            mTmpRunningTask = null;
        }
        toggleOrientationEventListener();
    }

    private void toggleOrientationEventListener() {
        boolean canEnable = canEnableOverviewRotationAnimation() && mOverviewStateEnabled;
        UI_HELPER_EXECUTOR.execute(() -> {
            if (canEnable) {
                mOrientationListener.enable();
            } else {
                mOrientationListener.disable();
            }
        });
    }

    private boolean canEnableOverviewRotationAnimation() {
        return supportsVerticalLandscape() // not 3P launcher
                && !TestProtocol.sDisableSensorRotation // Ignore hardware dependency for tests..
                && mOrientationListener.canDetectOrientation() // ..but does the hardware even work?
                && !mOrientationState.canLauncherAutoRotate(); // launcher is going to rotate itself
                && (mOrientationState.isSystemRotationAllowed() &&
                    !mOrientationState.canLauncherRotate()); // launcher is going to rotate itself
    }

    public void onDigitalWellbeingToastShown() {
+36 −10
Original line number Diff line number Diff line
@@ -51,6 +51,8 @@ import com.android.launcher3.touch.PagedOrientationHandler;
import com.android.launcher3.touch.PortraitPagedViewHandler;

import java.lang.annotation.Retention;
import java.util.ArrayList;
import java.util.List;

/**
 * Container to hold orientation/rotation related information for Launcher.
@@ -81,6 +83,10 @@ public final class RecentsOrientedState implements SharedPreferences.OnSharedPre
    private @SurfaceRotation int mDisplayRotation = ROTATION_0;
    private @SurfaceRotation int mLauncherRotation = Surface.ROTATION_0;

    public interface SystemRotationChangeListener {
        void onSystemRotationChanged(boolean enabled);
    }

    /**
     * If {@code true} we default to {@link PortraitPagedViewHandler} and don't support any fake
     * launcher orientations.
@@ -93,6 +99,7 @@ public final class RecentsOrientedState implements SharedPreferences.OnSharedPre
    private final SharedPreferences mSharedPrefs;
    private final boolean mAllowConfigurationDefaultValue;

    private List<SystemRotationChangeListener> mSystemRotationChangeListeners = new ArrayList<>();

    private final Matrix mTmpMatrix = new Matrix();
    private final Matrix mTmpInverseMatrix = new Matrix();
@@ -167,14 +174,6 @@ public final class RecentsOrientedState implements SharedPreferences.OnSharedPre
        return true;
    }

    public boolean areMultipleLayoutOrientationsDisabled() {
        return mDisableMultipleOrientations;
    }

    public boolean canLauncherAutoRotate() {
        return mIsHomeRotationAllowed && mIsSystemRotationAllowed;
    }

    /**
     * Setting this preference renders future calls to {@link #update(int, int, int)} as a no-op.
     */
@@ -198,6 +197,10 @@ public final class RecentsOrientedState implements SharedPreferences.OnSharedPre
        } catch (Settings.SettingNotFoundException e) {
            Log.e(TAG, "autorotate setting not found", e);
        }

        for (SystemRotationChangeListener listener : mSystemRotationChangeListeners) {
            listener.onSystemRotationChanged(mIsSystemRotationAllowed);
        }
    }

    private void updateHomeRotationSetting() {
@@ -205,6 +208,15 @@ public final class RecentsOrientedState implements SharedPreferences.OnSharedPre
                mAllowConfigurationDefaultValue);
    }

    public void addSystemRotationChangeListener(SystemRotationChangeListener listener) {
        mSystemRotationChangeListeners.add(listener);
        listener.onSystemRotationChanged(mIsSystemRotationAllowed);
    }

    public void removeSystemRotationChangeListener(SystemRotationChangeListener listener) {
        mSystemRotationChangeListeners.remove(listener);
    }

    public void init() {
        mSharedPrefs.registerOnSharedPreferenceChangeListener(this);
        mContentResolver.registerContentObserver(
@@ -217,6 +229,7 @@ public final class RecentsOrientedState implements SharedPreferences.OnSharedPre
    public void destroy() {
        mSharedPrefs.unregisterOnSharedPreferenceChangeListener(this);
        mContentResolver.unregisterContentObserver(mSystemAutoRotateObserver);
        mSystemRotationChangeListeners.clear();
    }

    @SurfaceRotation
@@ -229,12 +242,25 @@ public final class RecentsOrientedState implements SharedPreferences.OnSharedPre
        return mTouchRotation;
    }

    @SurfaceRotation
    public int getLauncherRotation() {
        return mLauncherRotation;
    }

    public boolean areMultipleLayoutOrientationsDisabled() {
        return mDisableMultipleOrientations;
    }

    public boolean isSystemRotationAllowed() {
        return mIsSystemRotationAllowed;
    }

    public boolean isHomeRotationAllowed() {
        return mIsHomeRotationAllowed;
    }

    public int getLauncherRotation() {
        return mLauncherRotation;
    public boolean canLauncherRotate() {
        return isSystemRotationAllowed() && isHomeRotationAllowed();
    }

    public int getTouchRotationDegrees() {