Commit b62a6f08 authored by Friedrich Horschig's avatar Friedrich Horschig Committed by Commit Bot

[Android] Prevent division by zero in Bottom Sheet

If the state changes while or briefly after the bottom sheet is hidden,
the BottomSheet#sendOffsetChangeEvents triggers without sheet content
which sets the maximum full ratio to 0.
Since the hidden full ration is divided by that maximum full ration, the
result is NaN which is then propagated to Observers [1].

[1] Sample stack trace of an Observer receiving NaN after onLayout:
BottomContainer${EmptyBottomSheetObserver}#onSheetOffsetChanged(NaN, 0);
        at Rz1.a(PG:2)
        at org.chromium.chrome.browser.widget.bottomsheet.BottomSheet.a(PG:102)
        at org.chromium.chrome.browser.widget.bottomsheet.BottomSheet.a(PG:127)
        at TV1.onLayoutChange(PG:40)
        at android.view.View.layout(View.java:19677)
        at android.view.ViewGroup.layout(ViewGroup.java:6075)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:261)

Bug: 1021885
Change-Id: I21573d91b92f1c017ec2267381c196ae79903545
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1901566Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Commit-Queue: Friedrich [CET] <fhorschig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713381}
parent c56c2bb0
......@@ -927,8 +927,10 @@ public class BottomSheet
mContainerHeight > 0 ? offsetWithBrowserControls / (float) mContainerHeight : 0;
// This ratio is relative to the peek and full positions of the sheet.
float hiddenFullRatio = MathUtils.clamp(
(screenRatio - getHiddenRatio()) / (getFullRatio() - getHiddenRatio()), 0, 1);
float maxHiddenFullRatio = getFullRatio() - getHiddenRatio();
float hiddenFullRatio = maxHiddenFullRatio == 0
? 0
: MathUtils.clamp((screenRatio - getHiddenRatio()) / maxHiddenFullRatio, 0, 1);
if (offsetWithBrowserControls < getSheetHeightForState(SheetState.HIDDEN)) {
mLastOffsetRatioSent = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment