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

Commit 4fea36f8 authored by Kyunglyul Hyun's avatar Kyunglyul Hyun
Browse files

Remove timeout from CONNECTING

The battery state machine connects to
a remote GATT server in an opportunistic way.
Therefore, there is a chance that the connection
is made after the timeout, which is totally valid.

This change removes timeout so it can wait indefinitely
for other GATT client is connected.

Bug: 261465867
Test: atest BluetoothInstrumentationTests
Change-Id: I522da76de9666db8384f51f72f6078fd8f8dd60e
parent 349be0e7
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -333,7 +333,6 @@ public class BatteryStateMachine extends StateMachine {
        public void enter() {
            log(TAG, "Enter (" + mDevice + "): "
                    + messageWhatToString(getCurrentMessage().what));
            sendMessageDelayed(CONNECT_TIMEOUT, sConnectTimeoutMs);
            dispatchConnectionStateChanged(mLastConnectionState, BluetoothProfile.STATE_CONNECTING);
        }

@@ -342,7 +341,6 @@ public class BatteryStateMachine extends StateMachine {
            log(TAG, "Exit (" + mDevice + "): "
                    + messageWhatToString(getCurrentMessage().what));
            mLastConnectionState = BluetoothProfile.STATE_CONNECTING;
            removeMessages(CONNECT_TIMEOUT);
        }

        @Override
@@ -355,8 +353,8 @@ public class BatteryStateMachine extends StateMachine {
                    Log.w(TAG, "CONNECT ignored: " + mDevice);
                    break;
                case CONNECT_TIMEOUT:
                    Log.w(TAG, "Connection timeout: " + mDevice);
                    // fall through
                    Log.e(TAG, "Connection timeout unexpected: " + mDevice);
                    break;
                case DISCONNECT:
                    log(TAG, "Connection canceled to " + mDevice);
                    if (mBluetoothGatt != null) {
+0 −26
Original line number Diff line number Diff line
@@ -55,7 +55,6 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;

@@ -278,31 +277,6 @@ public class BatteryStateMachineTest {
                .isInstanceOf(BatteryStateMachine.Connected.class);
    }

    @Test
    public void testConnectGattTimeout() {
        allowConnection(true);
        allowConnectGatt(true);

        // Inject an event for when incoming connection is requested
        mBatteryStateMachine.sendMessage(BatteryStateMachine.CONNECT);

        verify(mBatteryService, timeout(TIMEOUT_MS))
                .handleConnectionStateChanged(any(BatteryStateMachine.class),
                        eq(BluetoothProfile.STATE_DISCONNECTED),
                        eq(BluetoothProfile.STATE_CONNECTING));

        Assert.assertThat(mBatteryStateMachine.getCurrentState(),
                IsInstanceOf.instanceOf(BatteryStateMachine.Connecting.class));

        verify(mBatteryService, timeout(TIMEOUT_MS))
                .handleConnectionStateChanged(any(BatteryStateMachine.class),
                        eq(BluetoothProfile.STATE_CONNECTING),
                        eq(BluetoothProfile.STATE_DISCONNECTED));

        Assert.assertThat(mBatteryStateMachine.getCurrentState(),
                IsInstanceOf.instanceOf(BatteryStateMachine.Disconnected.class));
    }

    @Test
    public void testBatteryLevelChanged() {
        allowConnection(true);