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

Commit 2a3f5dee authored by Jeremy Sim's avatar Jeremy Sim
Browse files

Fix bug with launching non-50-50 splits in landscape on phones

This CL makes it so that DividerSnapAlgorithm.setDivideRatio() sets the middle position as a fallback when trying to fetch a non-existent snap target, instead of crashing.

The issue arose because it is possible to have a 30-70 split in Overview, then rotate to landscape, where 30-70 splits are not supported. Trying to launch the pair then resulted in a crash.

This change matches the behavior we already have when rotating a fullscreen 30-70 split to landscape, which is that the 30-70 split automatically converts to a 50-50 split.

Fixes: 326336840
Flag: N/A
Test: Does not crash anymore.
Change-Id: I68072c2816d5f6cf3a178b0f8def27cdc564d5d7
parent 6492191b
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -510,16 +510,18 @@ public final class SplitLayout implements DisplayInsetsController.OnInsetsChange
        }
    }

    /** Updates divide position and split bounds base on the ratio within root bounds. */
    /**
     * Updates divide position and split bounds base on the ratio within root bounds. Falls back
     * to middle position if the provided SnapTarget is not supported.
     */
    public void setDivideRatio(@PersistentSnapPosition int snapPosition) {
        final DividerSnapAlgorithm.SnapTarget snapTarget = mDividerSnapAlgorithm.findSnapTarget(
                snapPosition);

        if (snapTarget == null) {
            throw new IllegalArgumentException("No SnapTarget for position " + snapPosition);
        }

        setDividePosition(snapTarget.position, false /* applyLayoutChange */);
        setDividePosition(snapTarget != null
                ? snapTarget.position
                : mDividerSnapAlgorithm.getMiddleTarget().position,
                false /* applyLayoutChange */);
    }

    /** Resets divider position. */