Fix crash on connected devices settings

If disconnected bluetooth devices didn't exist in
recent devices, the index will return -1. Our condition
didn't check this situation, the IndexOutOfBoundsException
will throw when this case happens.

This CL adds the condition to check whether index is over
than or equal 0 to fix IndexOutOfBoundsException.

Bug: 173059077
Test: make -j42 RunSettingsRoboTests
Change-Id: Id93f4cb6bded83540045c5e8c21c6f6122a39fed
This commit is contained in:
Hugh Chen
2020-11-12 16:56:15 +08:00
parent b6bba3e9a2
commit 8f29850cca
2 changed files with 19 additions and 1 deletions

View File

@@ -144,7 +144,7 @@ public class PreviouslyConnectedDevicePreferenceController extends BasePreferenc
private void addPreference(int index, Preference preference) {
if (preference instanceof BluetoothDevicePreference) {
if (mDevicesList.size() >= index) {
if (index >= 0 && mDevicesList.size() >= index) {
mDevicesList.add(index, preference);
} else {
mDevicesList.add(preference);