From c0ce2e312a5bdf89b27347c2abfdd4b60721cf74 Mon Sep 17 00:00:00 2001 From: Mady Mellor Date: Tue, 2 May 2023 11:45:48 -0700 Subject: [PATCH] Fix possible num format exception when logging bubble stack position Test: treehugger Bug: 280455228 Change-Id: I6a647e10ab86a90c9b052e543a691642df0a3637 --- .../src/com/android/wm/shell/bubbles/BubbleStackView.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleStackView.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleStackView.java index b9ff5f0e820a4..c0c4fcb6d618b 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleStackView.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleStackView.java @@ -3319,7 +3319,9 @@ public class BubbleStackView extends FrameLayout * @return the normalized x-axis position of the bubble stack rounded to 4 decimal places. */ public float getNormalizedXPosition() { - return new BigDecimal(getStackPosition().x / mPositioner.getAvailableRect().width()) + int width = mPositioner.getAvailableRect().width(); + float stackPosition = width > 0 ? getStackPosition().x / width : 0; + return new BigDecimal(stackPosition) .setScale(4, RoundingMode.CEILING.HALF_UP) .floatValue(); } @@ -3328,7 +3330,9 @@ public class BubbleStackView extends FrameLayout * @return the normalized y-axis position of the bubble stack rounded to 4 decimal places. */ public float getNormalizedYPosition() { - return new BigDecimal(getStackPosition().y / mPositioner.getAvailableRect().height()) + int height = mPositioner.getAvailableRect().height(); + float stackPosition = height > 0 ? getStackPosition().y / height : 0; + return new BigDecimal(stackPosition) .setScale(4, RoundingMode.CEILING.HALF_UP) .floatValue(); }