Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4b7fb5df authored by LuK1337's avatar LuK1337
Browse files

SystemUI: Check List<CachedBluetoothDevice>.empty() before getting battery level

* This fixes a /rare/ unhandled IndexOutOfBoundsException
  shortly after connecting to a bluetooth device.

Change-Id: I9252df6dcb3ea93604ada9bd51d43f43d659bcb6
parent 6ee3e3a4
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ import android.util.Pair;
import com.android.internal.messages.nano.SystemMessageProto.SystemMessage;
import com.android.internal.telephony.IccCardConstants;
import com.android.internal.telephony.TelephonyIntents;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.systemui.Dependency;
import com.android.systemui.DockedStackExistsListener;
import com.android.systemui.R;
@@ -450,7 +451,9 @@ public class PhoneStatusBarPolicy implements Callback, Callbacks,
        boolean bluetoothVisible = false;
        if (mBluetooth != null) {
            if (mBluetooth.isBluetoothConnected()) {
                int batteryLevel = mBluetooth.getConnectedDevices().get(0).getBatteryLevel();
                List<CachedBluetoothDevice> connectedDevices = mBluetooth.getConnectedDevices();
                int batteryLevel = connectedDevices.isEmpty() ?
                        -1 : connectedDevices.get(0).getBatteryLevel();
                if (batteryLevel == 100) {
                    iconId = R.drawable.stat_sys_data_bluetooth_connected_battery_9;
                } else if (batteryLevel >= 90) {