Fix crash in LocalDisplayAdapter

findMatchingModeIdLocked can crash with ArrayIndexOutOfBounds
if passed a bad configId. In this situation will be better to
return NO_DISPLAY_MODE_ID and let the caller handle it.

This solves random restarts when hotplug reconnect events are
send for AndroidTV devices. The root cause for this is
getDesiredDisplayConfigSpecs returning an outdated baseModeId
after the list of supported display modes was updated after
hotplug.

Bug: 167966667
Test: manual
Change-Id: I92f5da0ef2539b0a02d9ad6da46fa095eaab1650
This commit is contained in:
Marin Shalamanov
2020-10-09 22:00:45 +02:00
parent 3142e68403
commit da438a1da4

View File

@@ -969,6 +969,10 @@ final class LocalDisplayAdapter extends DisplayAdapter {
}
private int findMatchingModeIdLocked(int configId) {
if (configId < 0 || configId >= mDisplayConfigs.length) {
Slog.e(TAG, "Invalid display config index " + configId);
return NO_DISPLAY_MODE_ID;
}
SurfaceControl.DisplayConfig config = mDisplayConfigs[configId];
for (int i = 0; i < mSupportedModes.size(); i++) {
DisplayModeRecord record = mSupportedModes.valueAt(i);