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

Commit c68b1235 authored by William Escande's avatar William Escande
Browse files

ErrorProne: TruthConstantAsserts

Bug: 344658662
Test: m BluetoothInstrumentationTests
Flag: Exempt refactor
Change-Id: I67158ab5afa3b7112d3296779a8e84f18bbfaba7
parent 78c247a3
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -78,6 +78,7 @@ java_defaults {
            "-Xep:ReturnAtTheEndOfVoidFunction:ERROR",
            "-Xep:StringCaseLocaleUsage:ERROR",
            "-Xep:StringCharset:ERROR",
            "-Xep:TruthConstantAsserts:ERROR",
            "-Xep:TruthIncompatibleType:ERROR",
            "-Xep:UnnecessaryAssignment:ERROR",
            "-Xep:UnnecessaryAsync:ERROR",
+2 −3
Original line number Diff line number Diff line
@@ -1279,9 +1279,8 @@ public class BassClientServiceTest {
    private void verifyConnectionStateIntent(
            int timeoutMs, BluetoothDevice device, int newState, int prevState) {
        Intent intent = TestUtils.waitForIntent(timeoutMs, mIntentQueue.get(device));
        assertThat(intent).isNotNull();
        assertThat(BluetoothLeBroadcastAssistant.ACTION_CONNECTION_STATE_CHANGED)
                .isEqualTo(intent.getAction());
        assertThat(intent.getAction())
                .isEqualTo(BluetoothLeBroadcastAssistant.ACTION_CONNECTION_STATE_CHANGED);
        assertThat(device).isEqualTo(intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE));
        assertThat(newState).isEqualTo(intent.getIntExtra(BluetoothProfile.EXTRA_STATE, -1));
        assertThat(prevState)
+42 −42
Original line number Diff line number Diff line
@@ -680,15 +680,15 @@ public class LeAudioServiceTest {
                mLeftDevice,
                BluetoothProfile.STATE_DISCONNECTING,
                BluetoothProfile.STATE_CONNECTED);
        assertThat(BluetoothProfile.STATE_DISCONNECTING)
                .isEqualTo(mService.getConnectionState(mLeftDevice));
        assertThat(mService.getConnectionState(mLeftDevice))
                .isEqualTo(BluetoothProfile.STATE_DISCONNECTING);
        verifyConnectionStateIntent(
                TIMEOUT_MS,
                mRightDevice,
                BluetoothProfile.STATE_DISCONNECTING,
                BluetoothProfile.STATE_CONNECTED);
        assertThat(BluetoothProfile.STATE_DISCONNECTING)
                .isEqualTo(mService.getConnectionState(mRightDevice));
        assertThat(mService.getConnectionState(mRightDevice))
                .isEqualTo(BluetoothProfile.STATE_DISCONNECTING);

        // Send a message to trigger disconnection completed
        connCompletedEvent =
@@ -703,8 +703,8 @@ public class LeAudioServiceTest {
                mLeftDevice,
                BluetoothProfile.STATE_DISCONNECTED,
                BluetoothProfile.STATE_DISCONNECTING);
        assertThat(BluetoothProfile.STATE_DISCONNECTED)
                .isEqualTo(mService.getConnectionState(mLeftDevice));
        assertThat(mService.getConnectionState(mLeftDevice))
                .isEqualTo(BluetoothProfile.STATE_DISCONNECTED);

        // Send a message to trigger disconnection completed to the right device
        connCompletedEvent =
@@ -719,8 +719,8 @@ public class LeAudioServiceTest {
                mRightDevice,
                BluetoothProfile.STATE_DISCONNECTED,
                BluetoothProfile.STATE_DISCONNECTING);
        assertThat(BluetoothProfile.STATE_DISCONNECTED)
                .isEqualTo(mService.getConnectionState(mRightDevice));
        assertThat(mService.getConnectionState(mRightDevice))
                .isEqualTo(BluetoothProfile.STATE_DISCONNECTED);

        // Verify the list of connected devices
        assertThat(mService.getConnectedDevices().contains(mLeftDevice)).isFalse();
@@ -751,8 +751,8 @@ public class LeAudioServiceTest {
                mLeftDevice,
                BluetoothProfile.STATE_CONNECTING,
                BluetoothProfile.STATE_DISCONNECTED);
        assertThat(BluetoothProfile.STATE_CONNECTING)
                .isEqualTo(mService.getConnectionState(mLeftDevice));
        assertThat(mService.getConnectionState(mLeftDevice))
                .isEqualTo(BluetoothProfile.STATE_CONNECTING);
        assertThat(mService.getDevices().contains(mLeftDevice)).isTrue();

        // LeAudio stack event: CONNECTION_STATE_DISCONNECTED - state machine should be removed
@@ -760,8 +760,8 @@ public class LeAudioServiceTest {
                mLeftDevice,
                BluetoothProfile.STATE_DISCONNECTED,
                BluetoothProfile.STATE_CONNECTING);
        assertThat(BluetoothProfile.STATE_DISCONNECTED)
                .isEqualTo(mService.getConnectionState(mLeftDevice));
        assertThat(mService.getConnectionState(mLeftDevice))
                .isEqualTo(BluetoothProfile.STATE_DISCONNECTED);
        assertThat(mService.getDevices().contains(mLeftDevice)).isTrue();
        mService.bondStateChanged(mLeftDevice, BluetoothDevice.BOND_NONE);
        assertThat(mService.getDevices().contains(mLeftDevice)).isFalse();
@@ -777,15 +777,15 @@ public class LeAudioServiceTest {
        // stack event: CONNECTION_STATE_CONNECTED - state machine should be created
        generateConnectionMessageFromNative(
                mLeftDevice, BluetoothProfile.STATE_CONNECTED, BluetoothProfile.STATE_CONNECTING);
        assertThat(BluetoothProfile.STATE_CONNECTED)
                .isEqualTo(mService.getConnectionState(mLeftDevice));
        assertThat(mService.getConnectionState(mLeftDevice))
                .isEqualTo(BluetoothProfile.STATE_CONNECTED);
        assertThat(mService.getDevices().contains(mLeftDevice)).isTrue();

        // stack event: CONNECTION_STATE_DISCONNECTED - state machine should be removed
        generateConnectionMessageFromNative(
                mLeftDevice, BluetoothProfile.STATE_DISCONNECTED, BluetoothProfile.STATE_CONNECTED);
        assertThat(BluetoothProfile.STATE_DISCONNECTED)
                .isEqualTo(mService.getConnectionState(mLeftDevice));
        assertThat(mService.getConnectionState(mLeftDevice))
                .isEqualTo(BluetoothProfile.STATE_DISCONNECTED);
        assertThat(mService.getDevices().contains(mLeftDevice)).isTrue();
        mService.bondStateChanged(mLeftDevice, BluetoothDevice.BOND_NONE);
        assertThat(mService.getDevices().contains(mLeftDevice)).isFalse();
@@ -793,16 +793,16 @@ public class LeAudioServiceTest {
        // stack event: CONNECTION_STATE_DISCONNECTING - state machine should not be created
        generateUnexpectedConnectionMessageFromNative(
                mLeftDevice, BluetoothProfile.STATE_DISCONNECTING);
        assertThat(BluetoothProfile.STATE_DISCONNECTED)
                .isEqualTo(mService.getConnectionState(mLeftDevice));
        assertThat(mService.getConnectionState(mLeftDevice))
                .isEqualTo(BluetoothProfile.STATE_DISCONNECTED);
        assertThat(mService.getDevices().contains(mLeftDevice)).isFalse();

        // stack event: CONNECTION_STATE_DISCONNECTED - state machine should not be created
        generateUnexpectedConnectionMessageFromNative(
                mLeftDevice,
                BluetoothProfile.STATE_DISCONNECTED);
        assertThat(BluetoothProfile.STATE_DISCONNECTED)
                .isEqualTo(mService.getConnectionState(mLeftDevice));
        assertThat(mService.getConnectionState(mLeftDevice))
                .isEqualTo(BluetoothProfile.STATE_DISCONNECTED);
        assertThat(mService.getDevices().contains(mLeftDevice)).isFalse();
    }

@@ -1037,8 +1037,8 @@ public class LeAudioServiceTest {
                mLeftDevice,
                BluetoothProfile.STATE_CONNECTING,
                BluetoothProfile.STATE_DISCONNECTED);
        assertThat(BluetoothProfile.STATE_CONNECTING)
                .isEqualTo(mService.getConnectionState(mLeftDevice));
        assertThat(mService.getConnectionState(mLeftDevice))
                .isEqualTo(BluetoothProfile.STATE_CONNECTING);
        assertThat(mService.getDevices().contains(mLeftDevice)).isTrue();

        // LeAudio stack event: CONNECTION_STATE_DISCONNECTED - state machine is not removed
@@ -1046,8 +1046,8 @@ public class LeAudioServiceTest {
                mLeftDevice,
                BluetoothProfile.STATE_DISCONNECTED,
                BluetoothProfile.STATE_CONNECTING);
        assertThat(BluetoothProfile.STATE_DISCONNECTED)
                .isEqualTo(mService.getConnectionState(mLeftDevice));
        assertThat(mService.getConnectionState(mLeftDevice))
                .isEqualTo(BluetoothProfile.STATE_DISCONNECTED);
        assertThat(mService.getDevices().contains(mLeftDevice)).isTrue();

        // LeAudio stack event: CONNECTION_STATE_CONNECTING - state machine remains
@@ -1055,8 +1055,8 @@ public class LeAudioServiceTest {
                mLeftDevice,
                BluetoothProfile.STATE_CONNECTING,
                BluetoothProfile.STATE_DISCONNECTED);
        assertThat(BluetoothProfile.STATE_CONNECTING)
                .isEqualTo(mService.getConnectionState(mLeftDevice));
        assertThat(mService.getConnectionState(mLeftDevice))
                .isEqualTo(BluetoothProfile.STATE_CONNECTING);
        assertThat(mService.getDevices().contains(mLeftDevice)).isTrue();

        // Device bond state marked as unbond - state machine is not removed
@@ -1070,8 +1070,8 @@ public class LeAudioServiceTest {
                mLeftDevice,
                BluetoothProfile.STATE_DISCONNECTED,
                BluetoothProfile.STATE_CONNECTING);
        assertThat(BluetoothProfile.STATE_DISCONNECTED)
                .isEqualTo(mService.getConnectionState(mLeftDevice));
        assertThat(mService.getConnectionState(mLeftDevice))
                .isEqualTo(BluetoothProfile.STATE_DISCONNECTED);
        assertThat(mService.getDevices().contains(mLeftDevice)).isFalse();
    }

@@ -1094,8 +1094,8 @@ public class LeAudioServiceTest {
                device,
                BluetoothProfile.STATE_CONNECTING,
                BluetoothProfile.STATE_DISCONNECTED);
        assertThat(BluetoothProfile.STATE_CONNECTING)
                .isEqualTo(mService.getConnectionState(device));
        assertThat(mService.getConnectionState(device))
                .isEqualTo(BluetoothProfile.STATE_CONNECTING);

        // Send a message to trigger connection completed
        connCompletedEvent =
@@ -1110,7 +1110,7 @@ public class LeAudioServiceTest {
                device,
                BluetoothProfile.STATE_CONNECTED,
                BluetoothProfile.STATE_CONNECTING);
        assertThat(BluetoothProfile.STATE_CONNECTED).isEqualTo(mService.getConnectionState(device));
        assertThat(mService.getConnectionState(device)).isEqualTo(BluetoothProfile.STATE_CONNECTED);

        // Verify that the device is in the list of connected devices
        assertThat(mService.getConnectedDevices().contains(device)).isTrue();
@@ -1203,8 +1203,8 @@ public class LeAudioServiceTest {
                mSingleDevice,
                BluetoothProfile.STATE_CONNECTING,
                BluetoothProfile.STATE_DISCONNECTED);
        assertThat(BluetoothProfile.STATE_CONNECTING)
                .isEqualTo(mService.getConnectionState(mSingleDevice));
        assertThat(mService.getConnectionState(mSingleDevice))
                .isEqualTo(BluetoothProfile.STATE_CONNECTING);

        LeAudioStackEvent connCompletedEvent;
        // Send a message to trigger connection completed
@@ -1220,8 +1220,8 @@ public class LeAudioServiceTest {
                mSingleDevice,
                BluetoothProfile.STATE_CONNECTED,
                BluetoothProfile.STATE_CONNECTING);
        assertThat(BluetoothProfile.STATE_CONNECTED)
                .isEqualTo(mService.getConnectionState(mSingleDevice));
        assertThat(mService.getConnectionState(mSingleDevice))
                .isEqualTo(BluetoothProfile.STATE_CONNECTED);

        // Set connection policy to forbidden
        assertThat(
@@ -1247,8 +1247,8 @@ public class LeAudioServiceTest {
                mSingleDevice,
                BluetoothProfile.STATE_DISCONNECTING,
                BluetoothProfile.STATE_CONNECTED);
        assertThat(BluetoothProfile.STATE_DISCONNECTING)
                .isEqualTo(mService.getConnectionState(mSingleDevice));
        assertThat(mService.getConnectionState(mSingleDevice))
                .isEqualTo(BluetoothProfile.STATE_DISCONNECTING);

        // Send a message to trigger disconnection completed
        connCompletedEvent =
@@ -1263,8 +1263,8 @@ public class LeAudioServiceTest {
                mSingleDevice,
                BluetoothProfile.STATE_DISCONNECTED,
                BluetoothProfile.STATE_DISCONNECTING);
        assertThat(BluetoothProfile.STATE_DISCONNECTED)
                .isEqualTo(mService.getConnectionState(mSingleDevice));
        assertThat(mService.getConnectionState(mSingleDevice))
                .isEqualTo(BluetoothProfile.STATE_DISCONNECTED);
    }

    /**
@@ -1292,8 +1292,8 @@ public class LeAudioServiceTest {
                device,
                BluetoothProfile.STATE_CONNECTING,
                BluetoothProfile.STATE_DISCONNECTED);
        assertThat(BluetoothProfile.STATE_CONNECTING)
                .isEqualTo(mService.getConnectionState(device));
        assertThat(mService.getConnectionState(device))
                .isEqualTo(BluetoothProfile.STATE_CONNECTING);

        // Use connected event to indicate that device is connected
        LeAudioStackEvent connCompletedEvent =
@@ -1308,7 +1308,7 @@ public class LeAudioServiceTest {
                BluetoothProfile.STATE_CONNECTED,
                BluetoothProfile.STATE_CONNECTING);

        assertThat(BluetoothProfile.STATE_CONNECTED).isEqualTo(mService.getConnectionState(device));
        assertThat(mService.getConnectionState(device)).isEqualTo(BluetoothProfile.STATE_CONNECTED);

        LeAudioStackEvent nodeGroupAdded =
                new LeAudioStackEvent(LeAudioStackEvent.EVENT_TYPE_GROUP_NODE_STATUS_CHANGED);
+2 −4
Original line number Diff line number Diff line
@@ -31,12 +31,10 @@ import static org.mockito.Mockito.verify;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.HandlerThread;

import androidx.test.InstrumentationRegistry;
import androidx.test.filters.MediumTest;
import androidx.test.runner.AndroidJUnit4;

@@ -99,8 +97,8 @@ public class LeAudioStateMachineTest {
    /** Test that default state is disconnected */
    @Test
    public void testDefaultDisconnectedState() {
        assertThat(BluetoothProfile.STATE_DISCONNECTED)
                .isEqualTo(mLeAudioStateMachine.getConnectionState());
        assertThat(mLeAudioStateMachine.getConnectionState())
                .isEqualTo(BluetoothProfile.STATE_DISCONNECTED);
    }

    /**