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

Commit 52fbb37d authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Enforce GuardedBy errorprone in tests" into main

parents d9b3e7eb b6a511ce
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ java_defaults {
            "-Xep:EmptyCatch:ERROR",
            "-Xep:EqualsIncompatibleType:ERROR",
            "-Xep:FutureReturnValueIgnored:ERROR",
            "-Xep:GuardedBy:ERROR",
            "-Xep:InlineMeInliner:ERROR",
            "-Xep:InvalidBlockTag:ERROR",
            "-Xep:InvalidInlineTag:ERROR",
+13 −7
Original line number Diff line number Diff line
@@ -150,8 +150,10 @@ public class HapClientServiceTest {
        startService();
        mNativeCallback = new HapClientNativeCallback(mAdapterService, mService);
        mService.mFactory = mServiceFactory;
        synchronized (mService.mCallbacks) {
            mService.mCallbacks.register(mFrameworkCallback);
        }
    }

    @After
    public void tearDown() throws Exception {
@@ -159,7 +161,9 @@ public class HapClientServiceTest {
            return;
        }

        synchronized (mService.mCallbacks) {
            mService.mCallbacks.unregister(mFrameworkCallback);
        }

        stopService();
    }
@@ -800,6 +804,7 @@ public class HapClientServiceTest {
        Binder binder = Mockito.mock(Binder.class);
        when(callback.asBinder()).thenReturn(binder);

        synchronized (mService.mCallbacks) {
            int size = mService.mCallbacks.getRegisteredCallbackCount();
            mService.registerCallback(callback);
            Assert.assertEquals(size + 1, mService.mCallbacks.getRegisteredCallbackCount());
@@ -807,6 +812,7 @@ public class HapClientServiceTest {
            mService.unregisterCallback(callback);
            Assert.assertEquals(size, mService.mCallbacks.getRegisteredCallbackCount());
        }
    }

    @Test
    public void testDumpDoesNotCrash() {
+27 −9
Original line number Diff line number Diff line
@@ -346,7 +346,9 @@ public class LeAudioBroadcastServiceTest {
        int broadcastId = 243;
        byte[] code = {0x00, 0x01, 0x00, 0x02};

        synchronized (mService.mBroadcastCallbacks) {
            mService.mBroadcastCallbacks.register(mCallbacks);
        }

        BluetoothLeAudioContentMetadata.Builder meta_builder =
                new BluetoothLeAudioContentMetadata.Builder();
@@ -362,7 +364,9 @@ public class LeAudioBroadcastServiceTest {
        int broadcastId = 243;
        byte[] code = {0x00, 0x01, 0x00, 0x02};

        synchronized (mService.mBroadcastCallbacks) {
            mService.mBroadcastCallbacks.register(mCallbacks);
        }

        BluetoothLeAudioContentMetadata.Builder meta_builder =
                new BluetoothLeAudioContentMetadata.Builder();
@@ -378,7 +382,9 @@ public class LeAudioBroadcastServiceTest {
        int broadcastId = 243;
        byte[] code = {0x00, 0x01, 0x00, 0x02};

        synchronized (mService.mBroadcastCallbacks) {
            mService.mBroadcastCallbacks.register(mCallbacks);
        }

        BluetoothLeAudioContentMetadata.Builder meta_builder =
                new BluetoothLeAudioContentMetadata.Builder();
@@ -422,7 +428,9 @@ public class LeAudioBroadcastServiceTest {
        int broadcastId = 243;
        byte[] code = {0x00, 0x01, 0x00, 0x02};

        synchronized (mService.mBroadcastCallbacks) {
            mService.mBroadcastCallbacks.register(mCallbacks);
        }

        BluetoothLeAudioContentMetadata.Builder meta_builder =
                new BluetoothLeAudioContentMetadata.Builder();
@@ -478,7 +486,9 @@ public class LeAudioBroadcastServiceTest {
        int groupId = 1;
        prepareConnectedUnicastDevice(groupId);

        synchronized (mService.mBroadcastCallbacks) {
            mService.mBroadcastCallbacks.register(mCallbacks);
        }

        BluetoothLeAudioContentMetadata.Builder meta_builder =
                new BluetoothLeAudioContentMetadata.Builder();
@@ -515,7 +525,9 @@ public class LeAudioBroadcastServiceTest {
        int broadcastId = 243;
        byte[] code = {0x00, 0x01, 0x00, 0x02};

        synchronized (mService.mBroadcastCallbacks) {
            mService.mBroadcastCallbacks.register(mCallbacks);
        }

        BluetoothLeAudioContentMetadata.Builder meta_builder =
                new BluetoothLeAudioContentMetadata.Builder();
@@ -531,7 +543,9 @@ public class LeAudioBroadcastServiceTest {
    public void testBroadcastInvalidBroadcastIdRequest() {
        int broadcastId = 243;

        synchronized (mService.mBroadcastCallbacks) {
            mService.mBroadcastCallbacks.register(mCallbacks);
        }

        // Stop non-existing broadcast
        mService.stopBroadcast(broadcastId);
@@ -837,7 +851,9 @@ public class LeAudioBroadcastServiceTest {
        int broadcastId = 243;
        byte[] code = {0x00, 0x01, 0x00, 0x02};

        synchronized (mService.mBroadcastCallbacks) {
            mService.mBroadcastCallbacks.register(mCallbacks);
        }

        BluetoothLeAudioContentMetadata.Builder meta_builder =
                new BluetoothLeAudioContentMetadata.Builder();
@@ -868,7 +884,9 @@ public class LeAudioBroadcastServiceTest {
        mSetFlagsRule.enableFlags(Flags.FLAG_AUDIO_ROUTING_CENTRALIZATION);
        mSetFlagsRule.enableFlags(Flags.FLAG_LEAUDIO_BROADCAST_AUDIO_HANDOVER_POLICIES);

        synchronized (mService.mBroadcastCallbacks) {
            mService.mBroadcastCallbacks.register(mCallbacks);
        }

        prepareConnectedUnicastDevice(groupId);

+26 −10
Original line number Diff line number Diff line
@@ -2047,7 +2047,9 @@ public class LeAudioServiceTest {
                    public void onGroupStreamStatusChanged(int groupId, int groupStreamStatus) {}
                };

        synchronized (mService.mLeAudioCallbacks) {
            mService.mLeAudioCallbacks.register(leAudioCallbacks);
        }

        injectGroupStatusChange(groupId, groupStatus);

@@ -2055,8 +2057,10 @@ public class LeAudioServiceTest {
        assertThat(onGroupStatusCallbackCalled).isTrue();

        onGroupStatusCallbackCalled = false;
        synchronized (mService.mLeAudioCallbacks) {
            mService.mLeAudioCallbacks.unregister(leAudioCallbacks);
        }
    }

    /** Test native interface group status message handling */
    @Test
@@ -2101,7 +2105,9 @@ public class LeAudioServiceTest {
                    }
                };

        synchronized (mService.mLeAudioCallbacks) {
            mService.mLeAudioCallbacks.register(leAudioCallbacks);
        }

        injectGroupStreamStatusChange(groupId, groupStreamStatus);

@@ -2109,8 +2115,10 @@ public class LeAudioServiceTest {
        assertThat(onGroupStreamStatusCallbackCalled).isTrue();

        onGroupStreamStatusCallbackCalled = false;
        synchronized (mService.mLeAudioCallbacks) {
            mService.mLeAudioCallbacks.unregister(leAudioCallbacks);
        }
    }

    /** Test native interface group stream status message handling */
    @Test
@@ -2210,7 +2218,9 @@ public class LeAudioServiceTest {
                    public void onGroupStreamStatusChanged(int groupId, int groupStreamStatus) {}
                };

        synchronized (mService.mLeAudioCallbacks) {
            mService.mLeAudioCallbacks.register(leAudioCallbacks);
        }

        injectGroupSelectableCodecConfigChanged(
                testGroupId, INPUT_SELECTABLE_CONFIG, OUTPUT_SELECTABLE_CONFIG);
@@ -2246,8 +2256,10 @@ public class LeAudioServiceTest {
                        any(), any(), any(BluetoothProfileConnectionInfo.class));

        onGroupCodecConfChangedCallbackCalled = false;
        synchronized (mService.mLeAudioCallbacks) {
            mService.mLeAudioCallbacks.unregister(leAudioCallbacks);
        }
    }

    /** Test native interface group status message handling */
    @Test
@@ -2290,7 +2302,7 @@ public class LeAudioServiceTest {
                    public void onGroupStreamStatusChanged(int groupId, int groupStreamStatus) {}
                };

        synchronized (this.mService.mLeAudioCallbacks) {
        synchronized (mService.mLeAudioCallbacks) {
            mService.mLeAudioCallbacks.register(leAudioCallbacks);
        }

@@ -2335,7 +2347,7 @@ public class LeAudioServiceTest {
                .handleBluetoothActiveDeviceChanged(
                        any(), any(), any(BluetoothProfileConnectionInfo.class));

        synchronized (this.mService.mLeAudioCallbacks) {
        synchronized (mService.mLeAudioCallbacks) {
            mService.mLeAudioCallbacks.unregister(leAudioCallbacks);
        }

@@ -2383,7 +2395,9 @@ public class LeAudioServiceTest {
                    public void onGroupStreamStatusChanged(int groupId, int groupStreamStatus) {}
                };

        synchronized (mService.mLeAudioCallbacks) {
            mService.mLeAudioCallbacks.register(leAudioCallbacks);
        }

        injectGroupSelectableCodecConfigChanged(
                testGroupId, INPUT_EMPTY_CONFIG, OUTPUT_SELECTABLE_CONFIG);
@@ -2393,7 +2407,9 @@ public class LeAudioServiceTest {
        assertThat(onGroupCodecConfChangedCallbackCalled).isTrue();

        onGroupCodecConfChangedCallbackCalled = false;
        synchronized (mService.mLeAudioCallbacks) {
            mService.mLeAudioCallbacks.unregister(leAudioCallbacks);
        }

        BluetoothLeAudioCodecStatus codecStatus = mService.getCodecStatus(testGroupId);
        assertThat(codecStatus.getInputCodecConfig()).isNull();
+33 −20
Original line number Diff line number Diff line
@@ -1201,13 +1201,15 @@ public class VolumeControlServiceTest {
        Binder binder = Mockito.mock(Binder.class);
        when(callback.asBinder()).thenReturn(binder);

        synchronized (mService.mCallbacks) {
            int size = mService.mCallbacks.getRegisteredCallbackCount();
        mServiceBinder.registerCallback(callback, mAttributionSource);
            mService.registerCallback(callback);
            Assert.assertEquals(size + 1, mService.mCallbacks.getRegisteredCallbackCount());

        mServiceBinder.unregisterCallback(callback, mAttributionSource);
            mService.unregisterCallback(callback);
            Assert.assertEquals(size, mService.mCallbacks.getRegisteredCallbackCount());
        }
    }

    @Test
    public void testServiceBinderRegisterCallbackWhenDeviceAlreadyConnected() throws Exception {
@@ -1269,9 +1271,11 @@ public class VolumeControlServiceTest {
        Binder binder = Mockito.mock(Binder.class);
        when(callback.asBinder()).thenReturn(binder);

        synchronized (mService.mCallbacks) {
            int size = mService.mCallbacks.getRegisteredCallbackCount();
        mServiceBinder.registerCallback(callback, mAttributionSource);
            mService.registerCallback(callback);
            Assert.assertEquals(size + 1, mService.mCallbacks.getRegisteredCallbackCount());
        }

        verify(callback).onVolumeOffsetChanged(eq(mDevice), eq(1), eq(100));
        verify(callback).onVolumeOffsetAudioLocationChanged(eq(mDevice), eq(1), eq(1));
@@ -1344,9 +1348,11 @@ public class VolumeControlServiceTest {
        Binder binder = Mockito.mock(Binder.class);
        when(callback.asBinder()).thenReturn(binder);

        synchronized (mService.mCallbacks) {
            int size = mService.mCallbacks.getRegisteredCallbackCount();
        mServiceBinder.registerCallback(callback, mAttributionSource);
            mService.registerCallback(callback);
            Assert.assertEquals(size + 1, mService.mCallbacks.getRegisteredCallbackCount());
        }

        verify(callback, times(1)).onDeviceVolumeChanged(eq(mDevice), eq(deviceOneVolume));
        verify(callback, times(1)).onDeviceVolumeChanged(eq(mDeviceTwo), eq(deviceTwoVolume));
@@ -1396,9 +1402,12 @@ public class VolumeControlServiceTest {
        Binder binder = Mockito.mock(Binder.class);
        when(callback.asBinder()).thenReturn(binder);

        int size = mService.mCallbacks.getRegisteredCallbackCount();
        mServiceBinder.registerCallback(callback, mAttributionSource);
        int size;
        synchronized (mService.mCallbacks) {
            size = mService.mCallbacks.getRegisteredCallbackCount();
            mService.registerCallback(callback);
            Assert.assertEquals(size + 1, mService.mCallbacks.getRegisteredCallbackCount());
        }

        IBluetoothVolumeControlCallback callback_new_client =
                Mockito.mock(IBluetoothVolumeControlCallback.class);
@@ -1406,13 +1415,15 @@ public class VolumeControlServiceTest {
        when(callback_new_client.asBinder()).thenReturn(binder_new_client);

        mServiceBinder.notifyNewRegisteredCallback(callback_new_client, mAttributionSource);
        synchronized (mService.mCallbacks) {
            Assert.assertEquals(size + 1, mService.mCallbacks.getRegisteredCallbackCount());
        }

        // This shall be done only once after mServiceBinder.registerCallback
        // This shall be done only once after mService.registerCallback
        verify(callback, times(1)).onDeviceVolumeChanged(eq(mDevice), eq(deviceOneVolume));
        verify(callback, times(1)).onDeviceVolumeChanged(eq(mDeviceTwo), eq(deviceTwoVolume));

        // This shall be done only once after mServiceBinder.updateNewRegistedCallback
        // This shall be done only once after mServiceBinder.updateNewRegisteredCallback
        verify(callback_new_client, times(1))
                .onDeviceVolumeChanged(eq(mDevice), eq(deviceOneVolume));
        verify(callback_new_client, times(1))
@@ -1510,9 +1521,11 @@ public class VolumeControlServiceTest {
        Binder binder = Mockito.mock(Binder.class);
        when(callback.asBinder()).thenReturn(binder);

        synchronized (mService.mCallbacks) {
            int size = mService.mCallbacks.getRegisteredCallbackCount();
        mServiceBinder.registerCallback(callback, mAttributionSource);
            mService.registerCallback(callback);
            Assert.assertEquals(size + 1, mService.mCallbacks.getRegisteredCallbackCount());
        }

        when(mLeAudioService.getGroupDevices(groupId))
                .thenReturn(Arrays.asList(mDevice, mDeviceTwo));