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

Commit 15cd1a81 authored by Kyunglyul Hyun's avatar Kyunglyul Hyun
Browse files

Don't use getCurrentState() in BatteryStateMachine

getCurrentState() could throw ArrayIndexOutOfBoundsException
when it's called during state transition.

To avoid exception we can use the last connection state instead.

Bug: 374013809
Flag: EXEMPT, no logic change
Test: atest BatterServiceTest BatteryStateMachineTest

Change-Id: I1cbbb4da6b16873b3f52d7d7c54c281413cde60d
parent b5c7187e
Loading
Loading
Loading
Loading
+2 −12
Original line number Diff line number Diff line
@@ -118,7 +118,7 @@ public class BatteryStateMachine extends StateMachine {
    }

    synchronized boolean isConnected() {
        return getCurrentState() == mConnected;
        return mLastConnectionState == BluetoothProfile.STATE_CONNECTED;
    }

    private static String messageWhatToString(int what) {
@@ -153,17 +153,7 @@ public class BatteryStateMachine extends StateMachine {

    @BluetoothProfile.BtProfileState
    int getConnectionState() {
        String currentState = getCurrentState().getName();
        return switch (currentState) {
            case "Disconnected" -> BluetoothProfile.STATE_DISCONNECTED;
            case "Connecting" -> BluetoothProfile.STATE_CONNECTING;
            case "Connected" -> BluetoothProfile.STATE_CONNECTED;
            case "Disconnecting" -> BluetoothProfile.STATE_DISCONNECTING;
            default -> {
                Log.e(TAG, "Bad currentState: " + currentState);
                yield BluetoothProfile.STATE_DISCONNECTED;
            }
        };
        return mLastConnectionState;
    }

    void dispatchConnectionStateChanged(int toState) {