From 45362a6b7255b24beb89b29162a334f73a341440 Mon Sep 17 00:00:00 2001 From: George Mount Date: Fri, 4 Aug 2017 10:17:36 -0700 Subject: [PATCH] Fix monkey bug when focus change before layout Bug 64359848 Monkey found a divide-by-zero error caused by the width not set when focus was changed before layout. This CL just ensures that there is no divide by zero by selecting the first row/column. Test: manually launched Date Picker and it didn't crash Change-Id: Id6dd12cd20b052af71ab980c8a694020ea679e7c --- core/java/android/widget/SimpleMonthView.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/java/android/widget/SimpleMonthView.java b/core/java/android/widget/SimpleMonthView.java index 855d1d288a653..9982732384dad 100644 --- a/core/java/android/widget/SimpleMonthView.java +++ b/core/java/android/widget/SimpleMonthView.java @@ -517,6 +517,8 @@ class SimpleMonthView extends View { private int findClosestRow(@Nullable Rect previouslyFocusedRect) { if (previouslyFocusedRect == null) { return 3; + } else if (mDayHeight == 0) { + return 0; // There hasn't been a layout, so just choose the first row } else { int centerY = previouslyFocusedRect.centerY(); @@ -545,6 +547,8 @@ class SimpleMonthView extends View { private int findClosestColumn(@Nullable Rect previouslyFocusedRect) { if (previouslyFocusedRect == null) { return DAYS_IN_WEEK / 2; + } else if (mCellWidth == 0) { + return 0; // There hasn't been a layout, so we can just choose the first column } else { int centerX = previouslyFocusedRect.centerX() - mPaddingLeft; final int columnFromLeft =