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

Commit a412c9e3 authored by Weilin Xu's avatar Weilin Xu
Browse files

Fix ConcurrentModificationException in radio test

In broadcast radio service unit tests testing cancel, tune was also
called and invoked callback calling
RadioServiceUserController.getCurrentUser in a separate thread. This
causes concurrent modification exception when the next unit test
modifies the way mocking getCurrentUser if the current test does not
wait for that callback is completed. To test cancel in unit test,
calling tune in advance is not needed since it is duty of HAL to cancel
previous tuning operations. Thus, tune operations in unit test for
cancel can be removed.

Bug: 302236983
Test: atest com.android.server.broadcastradio
Change-Id: Ib42f302386aab2c5fa4d6159c14402b4adcc2de1
parent e3f6f95c
Loading
Loading
Loading
Loading
+0 −5
Original line number Diff line number Diff line
@@ -610,8 +610,6 @@ public final class TunerSessionTest extends ExtendedRadioMockitoTestCase {
    @Test
    public void cancel() throws Exception {
        openAidlClients(/* numClients= */ 1);
        ProgramSelector initialSel = AidlTestUtils.makeFmSelector(AM_FM_FREQUENCY_LIST[1]);
        mTunerSessions[0].tune(initialSel);

        mTunerSessions[0].cancel();

@@ -621,9 +619,6 @@ public final class TunerSessionTest extends ExtendedRadioMockitoTestCase {
    @Test
    public void cancel_forNonCurrentUser_doesNotCancel() throws Exception {
        openAidlClients(/* numClients= */ 1);
        ProgramSelector initialSel = AidlTestUtils.makeFmSelector(AM_FM_FREQUENCY_LIST[1]);
        mTunerSessions[0].tune(initialSel);
        verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT).onCurrentProgramInfoChanged(any());
        doReturn(false).when(() -> RadioServiceUserController.isCurrentOrSystemUser());

        mTunerSessions[0].cancel();
+0 −5
Original line number Diff line number Diff line
@@ -540,8 +540,6 @@ public final class TunerSessionHidlTest extends ExtendedRadioMockitoTestCase {
    @Test
    public void cancel() throws Exception {
        openAidlClients(/* numClients= */ 1);
        ProgramSelector initialSel = TestUtils.makeFmSelector(AM_FM_FREQUENCY_LIST[1]);
        mTunerSessions[0].tune(initialSel);

        mTunerSessions[0].cancel();

@@ -551,9 +549,6 @@ public final class TunerSessionHidlTest extends ExtendedRadioMockitoTestCase {
    @Test
    public void cancel_forNonCurrentUser_doesNotCancel() throws Exception {
        openAidlClients(/* numClients= */ 1);
        ProgramSelector initialSel = TestUtils.makeFmSelector(AM_FM_FREQUENCY_LIST[1]);
        mTunerSessions[0].tune(initialSel);
        verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT).onCurrentProgramInfoChanged(any());
        doReturn(false).when(() -> RadioServiceUserController.isCurrentOrSystemUser());

        mTunerSessions[0].cancel();