Fix b/243746796 Crash when mouse hangs over an empty battery chart

Bug: 243746796
Fix: 243746796
Test: manual
Change-Id: I3e595c96a55f1114b50ed5ed8e49e962cc90cbde
Merged-In: I3e595c96a55f1114b50ed5ed8e49e962cc90cbde
This commit is contained in:
Zaiyue Xue
2022-08-25 13:41:24 +08:00
parent a0c76c92a1
commit fb3ebf8dc7

View File

@@ -595,6 +595,9 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
// Searches the corresponding trapezoid index from x location.
private int getTrapezoidIndex(float x) {
if (mTrapezoidSlots == null) {
return BatteryChartViewModel.SELECTED_INDEX_INVALID;
}
for (int index = 0; index < mTrapezoidSlots.length; index++) {
final TrapezoidSlot slot = mTrapezoidSlots[index];
if (x >= slot.mLeft - mTrapezoidHOffset