Loading core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/aidl/TunerSessionTest.java +33 −45 Original line number Original line Diff line number Diff line Loading @@ -16,20 +16,20 @@ package com.android.server.broadcastradio.aidl; package com.android.server.broadcastradio.aidl; import static com.android.dx.mockito.inline.extended.ExtendedMockito.after; import static com.android.dx.mockito.inline.extended.ExtendedMockito.any; import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyBoolean; import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyInt; import static com.android.dx.mockito.inline.extended.ExtendedMockito.doAnswer; import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; import static com.android.dx.mockito.inline.extended.ExtendedMockito.doThrow; import static com.android.dx.mockito.inline.extended.ExtendedMockito.eq; import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock; import static com.android.dx.mockito.inline.extended.ExtendedMockito.never; import static com.android.dx.mockito.inline.extended.ExtendedMockito.timeout; import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify; import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.app.compat.CompatChanges; import android.app.compat.CompatChanges; import android.graphics.Bitmap; import android.graphics.Bitmap; Loading Loading @@ -81,8 +81,8 @@ public final class TunerSessionTest extends ExtendedRadioMockitoTestCase { private static final int USER_ID_1 = 11; private static final int USER_ID_1 = 11; private static final int USER_ID_2 = 12; private static final int USER_ID_2 = 12; private static final VerificationWithTimeout CALLBACK_TIMEOUT = private static final int CALLBACK_TIMEOUT_MS = 200; timeout(/* millis= */ 200); private static final VerificationWithTimeout CALLBACK_TIMEOUT = timeout(CALLBACK_TIMEOUT_MS); private static final int SIGNAL_QUALITY = 90; private static final int SIGNAL_QUALITY = 90; private static final long AM_FM_FREQUENCY_SPACING = 500; private static final long AM_FM_FREQUENCY_SPACING = 500; private static final long[] AM_FM_FREQUENCY_LIST = {97_500, 98_100, 99_100}; private static final long[] AM_FM_FREQUENCY_LIST = {97_500, 98_100, 99_100}; Loading Loading @@ -166,12 +166,12 @@ public final class TunerSessionTest extends ExtendedRadioMockitoTestCase { @Before @Before public void setup() throws Exception { public void setup() throws Exception { when(mUserHandleMock.getIdentifier()).thenReturn(USER_ID_1); doReturn(true).when(() -> CompatChanges.isChangeEnabled( doReturn(true).when(() -> CompatChanges.isChangeEnabled( eq(ConversionUtils.RADIO_U_VERSION_REQUIRED), anyInt())); eq(ConversionUtils.RADIO_U_VERSION_REQUIRED), anyInt())); doReturn(USER_ID_1).when(mUserHandleMock).getIdentifier(); doReturn(mUserHandleMock).when(() -> Binder.getCallingUserHandle()); doReturn(true).when(() -> RadioServiceUserController.isCurrentOrSystemUser()); doReturn(true).when(() -> RadioServiceUserController.isCurrentOrSystemUser()); doReturn(USER_ID_1).when(() -> RadioServiceUserController.getCurrentUser()); doReturn(USER_ID_1).when(() -> RadioServiceUserController.getCurrentUser()); doReturn(mUserHandleMock).when(() -> Binder.getCallingUserHandle()); mRadioModule = new RadioModule(mBroadcastRadioMock, mRadioModule = new RadioModule(mBroadcastRadioMock, AidlTestUtils.makeDefaultModuleProperties()); AidlTestUtils.makeDefaultModuleProperties()); Loading Loading @@ -222,7 +222,7 @@ public final class TunerSessionTest extends ExtendedRadioMockitoTestCase { return Result.OK; return Result.OK; }).when(mBroadcastRadioMock).seek(anyBoolean(), anyBoolean()); }).when(mBroadcastRadioMock).seek(anyBoolean(), anyBoolean()); when(mBroadcastRadioMock.getImage(anyInt())).thenReturn(null); doReturn(null).when(mBroadcastRadioMock).getImage(anyInt()); doAnswer(invocation -> { doAnswer(invocation -> { int configFlag = (int) invocation.getArguments()[0]; int configFlag = (int) invocation.getArguments()[0]; Loading Loading @@ -275,7 +275,7 @@ public final class TunerSessionTest extends ExtendedRadioMockitoTestCase { mTunerSessions[0].setConfiguration(FM_BAND_CONFIG); mTunerSessions[0].setConfiguration(FM_BAND_CONFIG); verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT.times(0)) verify(mAidlTunerCallbackMocks[0], after(CALLBACK_TIMEOUT_MS).times(0)) .onConfigurationChanged(FM_BAND_CONFIG); .onConfigurationChanged(FM_BAND_CONFIG); } } Loading Loading @@ -446,25 +446,10 @@ public final class TunerSessionTest extends ExtendedRadioMockitoTestCase { mTunerSessions[0].tune(initialSel); mTunerSessions[0].tune(initialSel); verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT.times(0)) verify(mAidlTunerCallbackMocks[0], after(CALLBACK_TIMEOUT_MS).times(0)) .onCurrentProgramInfoChanged(tuneInfo); .onCurrentProgramInfoChanged(tuneInfo); } } @Test public void tune_forSystemUser() throws Exception { when(mUserHandleMock.getIdentifier()).thenReturn(UserHandle.USER_SYSTEM); doReturn(mUserHandleMock).when(() -> Binder.getCallingUserHandle()); doReturn(true).when(() -> RadioServiceUserController.isCurrentOrSystemUser()); ProgramSelector initialSel = AidlTestUtils.makeFmSelector(AM_FM_FREQUENCY_LIST[1]); RadioManager.ProgramInfo tuneInfo = AidlTestUtils.makeProgramInfo(initialSel, SIGNAL_QUALITY); openAidlClients(/* numClients= */ 1); mTunerSessions[0].tune(initialSel); verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT).onCurrentProgramInfoChanged(tuneInfo); } @Test @Test public void tune_withUnknownErrorFromHal_fails() throws Exception { public void tune_withUnknownErrorFromHal_fails() throws Exception { openAidlClients(/* numClients= */ 1); openAidlClients(/* numClients= */ 1); Loading Loading @@ -525,7 +510,7 @@ public final class TunerSessionTest extends ExtendedRadioMockitoTestCase { mTunerSessions[0].step(/* directionDown= */ true, /* skipSubChannel= */ false); mTunerSessions[0].step(/* directionDown= */ true, /* skipSubChannel= */ false); verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT.times(0)) verify(mAidlTunerCallbackMocks[0], after(CALLBACK_TIMEOUT_MS).times(0)) .onCurrentProgramInfoChanged(any()); .onCurrentProgramInfoChanged(any()); } } Loading Loading @@ -604,7 +589,7 @@ public final class TunerSessionTest extends ExtendedRadioMockitoTestCase { mTunerSessions[0].seek(/* directionDown= */ true, /* skipSubChannel= */ false); mTunerSessions[0].seek(/* directionDown= */ true, /* skipSubChannel= */ false); verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT.times(0)) verify(mAidlTunerCallbackMocks[0], after(CALLBACK_TIMEOUT_MS).times(0)) .onCurrentProgramInfoChanged(seekUpInfo); .onCurrentProgramInfoChanged(seekUpInfo); } } Loading Loading @@ -638,6 +623,7 @@ public final class TunerSessionTest extends ExtendedRadioMockitoTestCase { openAidlClients(/* numClients= */ 1); openAidlClients(/* numClients= */ 1); ProgramSelector initialSel = AidlTestUtils.makeFmSelector(AM_FM_FREQUENCY_LIST[1]); ProgramSelector initialSel = AidlTestUtils.makeFmSelector(AM_FM_FREQUENCY_LIST[1]); mTunerSessions[0].tune(initialSel); mTunerSessions[0].tune(initialSel); verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT).onCurrentProgramInfoChanged(any()); doReturn(false).when(() -> RadioServiceUserController.isCurrentOrSystemUser()); doReturn(false).when(() -> RadioServiceUserController.isCurrentOrSystemUser()); mTunerSessions[0].cancel(); mTunerSessions[0].cancel(); Loading Loading @@ -686,8 +672,8 @@ public final class TunerSessionTest extends ExtendedRadioMockitoTestCase { public void getImage_whenHalThrowsException_fails() throws Exception { public void getImage_whenHalThrowsException_fails() throws Exception { openAidlClients(/* numClients= */ 1); openAidlClients(/* numClients= */ 1); String exceptionMessage = "HAL service died."; String exceptionMessage = "HAL service died."; when(mBroadcastRadioMock.getImage(anyInt())) doThrow(new RemoteException(exceptionMessage)).when(mBroadcastRadioMock) .thenThrow(new RemoteException(exceptionMessage)); .getImage(anyInt()); RuntimeException thrown = assertThrows(RuntimeException.class, () -> { RuntimeException thrown = assertThrows(RuntimeException.class, () -> { mTunerSessions[0].getImage(/* id= */ 1); mTunerSessions[0].getImage(/* id= */ 1); Loading @@ -713,7 +699,8 @@ public final class TunerSessionTest extends ExtendedRadioMockitoTestCase { mTunerSessions[0].startBackgroundScan(); mTunerSessions[0].startBackgroundScan(); verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT.times(0)).onBackgroundScanComplete(); verify(mAidlTunerCallbackMocks[0], after(CALLBACK_TIMEOUT_MS).times(0)) .onBackgroundScanComplete(); } } @Test @Test Loading Loading @@ -905,7 +892,8 @@ public final class TunerSessionTest extends ExtendedRadioMockitoTestCase { mHalTunerCallback.onProgramListUpdated(AidlTestUtils.makeHalChunk(/* purge= */ false, mHalTunerCallback.onProgramListUpdated(AidlTestUtils.makeHalChunk(/* purge= */ false, /* complete= */ true, List.of(TEST_FM_INFO), new ArrayList<>())); /* complete= */ true, List.of(TEST_FM_INFO), new ArrayList<>())); verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT.times(0)).onProgramListUpdated(any()); verify(mAidlTunerCallbackMocks[0], after(CALLBACK_TIMEOUT_MS).times(0)) .onProgramListUpdated(any()); } } @Test @Test Loading Loading @@ -1160,8 +1148,8 @@ public final class TunerSessionTest extends ExtendedRadioMockitoTestCase { Map<String, String> parametersSet = Map.of("mockParam1", "mockValue1", Map<String, String> parametersSet = Map.of("mockParam1", "mockValue1", "mockParam2", "mockValue2"); "mockParam2", "mockValue2"); String exceptionMessage = "HAL service died."; String exceptionMessage = "HAL service died."; when(mBroadcastRadioMock.setParameters(any())) doThrow(new RemoteException(exceptionMessage)).when(mBroadcastRadioMock) .thenThrow(new RemoteException(exceptionMessage)); .setParameters(any()); RuntimeException thrown = assertThrows(RuntimeException.class, () -> { RuntimeException thrown = assertThrows(RuntimeException.class, () -> { mTunerSessions[0].setParameters(parametersSet); mTunerSessions[0].setParameters(parametersSet); Loading @@ -1186,8 +1174,8 @@ public final class TunerSessionTest extends ExtendedRadioMockitoTestCase { openAidlClients(/* numClients= */ 1); openAidlClients(/* numClients= */ 1); List<String> parameterKeys = List.of("mockKey1", "mockKey2"); List<String> parameterKeys = List.of("mockKey1", "mockKey2"); String exceptionMessage = "HAL service died."; String exceptionMessage = "HAL service died."; when(mBroadcastRadioMock.getParameters(any())) doThrow(new RemoteException(exceptionMessage)).when(mBroadcastRadioMock) .thenThrow(new RemoteException(exceptionMessage)); .getParameters(any()); RuntimeException thrown = assertThrows(RuntimeException.class, () -> { RuntimeException thrown = assertThrows(RuntimeException.class, () -> { mTunerSessions[0].getParameters(parameterKeys); mTunerSessions[0].getParameters(parameterKeys); Loading @@ -1198,7 +1186,7 @@ public final class TunerSessionTest extends ExtendedRadioMockitoTestCase { } } @Test @Test public void onCurrentProgramInfoChanged_withNoncurrentUser_doesNotInvokeCallback() public void onCurrentProgramInfoChanged_withNonCurrentUser_doesNotInvokeCallback() throws Exception { throws Exception { openAidlClients(1); openAidlClients(1); doReturn(USER_ID_2).when(() -> RadioServiceUserController.getCurrentUser()); doReturn(USER_ID_2).when(() -> RadioServiceUserController.getCurrentUser()); Loading @@ -1206,7 +1194,7 @@ public final class TunerSessionTest extends ExtendedRadioMockitoTestCase { mHalTunerCallback.onCurrentProgramInfoChanged(AidlTestUtils.makeHalProgramInfo( mHalTunerCallback.onCurrentProgramInfoChanged(AidlTestUtils.makeHalProgramInfo( AidlTestUtils.makeHalFmSelector(AM_FM_FREQUENCY_LIST[1]), SIGNAL_QUALITY)); AidlTestUtils.makeHalFmSelector(AM_FM_FREQUENCY_LIST[1]), SIGNAL_QUALITY)); verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT.times(0)) verify(mAidlTunerCallbackMocks[0], after(CALLBACK_TIMEOUT_MS).times(0)) .onCurrentProgramInfoChanged(any()); .onCurrentProgramInfoChanged(any()); } } Loading core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/hal2/TunerSessionHidlTest.java +28 −54 Original line number Original line Diff line number Diff line Loading @@ -16,22 +16,22 @@ package com.android.server.broadcastradio.hal2; package com.android.server.broadcastradio.hal2; import static com.android.dx.mockito.inline.extended.ExtendedMockito.after; import static com.android.dx.mockito.inline.extended.ExtendedMockito.any; import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyBoolean; import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyInt; import static com.android.dx.mockito.inline.extended.ExtendedMockito.doAnswer; import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; import static com.android.dx.mockito.inline.extended.ExtendedMockito.doThrow; import static com.android.dx.mockito.inline.extended.ExtendedMockito.eq; import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock; import static com.android.dx.mockito.inline.extended.ExtendedMockito.never; import static com.android.dx.mockito.inline.extended.ExtendedMockito.timeout; import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify; import static com.google.common.truth.Truth.assertWithMessage; import static com.google.common.truth.Truth.assertWithMessage; import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.graphics.Bitmap; import android.graphics.Bitmap; import android.hardware.broadcastradio.V2_0.Constants; import android.hardware.broadcastradio.V2_0.Constants; Loading Loading @@ -78,8 +78,8 @@ public final class TunerSessionHidlTest extends ExtendedRadioMockitoTestCase { private static final int USER_ID_1 = 11; private static final int USER_ID_1 = 11; private static final int USER_ID_2 = 12; private static final int USER_ID_2 = 12; private static final VerificationWithTimeout CALLBACK_TIMEOUT = private static final int CALLBACK_TIMEOUT_MS = 200; timeout(/* millis= */ 200); private static final VerificationWithTimeout CALLBACK_TIMEOUT = timeout(CALLBACK_TIMEOUT_MS); private static final int SIGNAL_QUALITY = 1; private static final int SIGNAL_QUALITY = 1; private static final long AM_FM_FREQUENCY_SPACING = 500; private static final long AM_FM_FREQUENCY_SPACING = 500; private static final long[] AM_FM_FREQUENCY_LIST = {97_500, 98_100, 99_100}; private static final long[] AM_FM_FREQUENCY_LIST = {97_500, 98_100, 99_100}; Loading Loading @@ -113,7 +113,7 @@ public final class TunerSessionHidlTest extends ExtendedRadioMockitoTestCase { @Before @Before public void setup() throws Exception { public void setup() throws Exception { when(mUserHandleMock.getIdentifier()).thenReturn(USER_ID_1); doReturn(USER_ID_1).when(mUserHandleMock).getIdentifier(); doReturn(mUserHandleMock).when(() -> Binder.getCallingUserHandle()); doReturn(mUserHandleMock).when(() -> Binder.getCallingUserHandle()); doReturn(true).when(() -> RadioServiceUserController.isCurrentOrSystemUser()); doReturn(true).when(() -> RadioServiceUserController.isCurrentOrSystemUser()); doReturn(USER_ID_1).when(() -> RadioServiceUserController.getCurrentUser()); doReturn(USER_ID_1).when(() -> RadioServiceUserController.getCurrentUser()); Loading Loading @@ -170,7 +170,7 @@ public final class TunerSessionHidlTest extends ExtendedRadioMockitoTestCase { return Result.OK; return Result.OK; }).when(mHalTunerSessionMock).scan(anyBoolean(), anyBoolean()); }).when(mHalTunerSessionMock).scan(anyBoolean(), anyBoolean()); when(mBroadcastRadioMock.getImage(anyInt())).thenReturn(new ArrayList<Byte>(0)); doReturn(new ArrayList<Byte>(0)).when(mBroadcastRadioMock).getImage(anyInt()); doAnswer(invocation -> { doAnswer(invocation -> { int configFlag = (int) invocation.getArguments()[0]; int configFlag = (int) invocation.getArguments()[0]; Loading Loading @@ -227,7 +227,7 @@ public final class TunerSessionHidlTest extends ExtendedRadioMockitoTestCase { mTunerSessions[0].setConfiguration(FM_BAND_CONFIG); mTunerSessions[0].setConfiguration(FM_BAND_CONFIG); verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT.times(0)) verify(mAidlTunerCallbackMocks[0], after(CALLBACK_TIMEOUT_MS).times(0)) .onConfigurationChanged(FM_BAND_CONFIG); .onConfigurationChanged(FM_BAND_CONFIG); } } Loading Loading @@ -379,7 +379,7 @@ public final class TunerSessionHidlTest extends ExtendedRadioMockitoTestCase { mTunerSessions[0].tune(initialSel); mTunerSessions[0].tune(initialSel); verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT.times(0)) verify(mAidlTunerCallbackMocks[0], after(CALLBACK_TIMEOUT_MS).times(0)) .onCurrentProgramInfoChanged(tuneInfo); .onCurrentProgramInfoChanged(tuneInfo); } } Loading @@ -397,20 +397,6 @@ public final class TunerSessionHidlTest extends ExtendedRadioMockitoTestCase { .that(thrown).hasMessageThat().contains(Result.toString(Result.UNKNOWN_ERROR)); .that(thrown).hasMessageThat().contains(Result.toString(Result.UNKNOWN_ERROR)); } } @Test public void tune_forSystemUser() throws Exception { when(mUserHandleMock.getIdentifier()).thenReturn(UserHandle.USER_SYSTEM); doReturn(mUserHandleMock).when(() -> Binder.getCallingUserHandle()); doReturn(true).when(() -> RadioServiceUserController.isCurrentOrSystemUser()); ProgramSelector initialSel = TestUtils.makeFmSelector(AM_FM_FREQUENCY_LIST[1]); RadioManager.ProgramInfo tuneInfo = TestUtils.makeProgramInfo(initialSel, SIGNAL_QUALITY); openAidlClients(/* numClients= */ 1); mTunerSessions[0].tune(initialSel); verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT).onCurrentProgramInfoChanged(tuneInfo); } @Test @Test public void step_withDirectionUp() throws Exception { public void step_withDirectionUp() throws Exception { long initFreq = AM_FM_FREQUENCY_LIST[1]; long initFreq = AM_FM_FREQUENCY_LIST[1]; Loading Loading @@ -455,7 +441,7 @@ public final class TunerSessionHidlTest extends ExtendedRadioMockitoTestCase { mTunerSessions[0].step(/* directionDown= */ true, /* skipSubChannel= */ false); mTunerSessions[0].step(/* directionDown= */ true, /* skipSubChannel= */ false); verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT.times(0)) verify(mAidlTunerCallbackMocks[0], after(CALLBACK_TIMEOUT_MS).times(0)) .onCurrentProgramInfoChanged(any()); .onCurrentProgramInfoChanged(any()); } } Loading Loading @@ -533,7 +519,7 @@ public final class TunerSessionHidlTest extends ExtendedRadioMockitoTestCase { mTunerSessions[0].seek(/* directionDown= */ true, /* skipSubChannel= */ false); mTunerSessions[0].seek(/* directionDown= */ true, /* skipSubChannel= */ false); verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT.times(0)) verify(mAidlTunerCallbackMocks[0], after(CALLBACK_TIMEOUT_MS).times(0)) .onCurrentProgramInfoChanged(seekUpInfo); .onCurrentProgramInfoChanged(seekUpInfo); } } Loading Loading @@ -562,18 +548,6 @@ public final class TunerSessionHidlTest extends ExtendedRadioMockitoTestCase { verify(mHalTunerSessionMock).cancel(); verify(mHalTunerSessionMock).cancel(); } } @Test public void cancel_forNonCurrentUser() throws Exception { openAidlClients(/* numClients= */ 1); ProgramSelector initialSel = TestUtils.makeFmSelector(AM_FM_FREQUENCY_LIST[1]); mTunerSessions[0].tune(initialSel); doReturn(false).when(() -> RadioServiceUserController.isCurrentOrSystemUser()); mTunerSessions[0].cancel(); verify(mHalTunerSessionMock, never()).cancel(); } @Test @Test public void cancel_forNonCurrentUser_doesNotCancel() throws Exception { public void cancel_forNonCurrentUser_doesNotCancel() throws Exception { openAidlClients(/* numClients= */ 1); openAidlClients(/* numClients= */ 1); Loading Loading @@ -627,8 +601,7 @@ public final class TunerSessionHidlTest extends ExtendedRadioMockitoTestCase { public void getImage_whenHalThrowsException_fails() throws Exception { public void getImage_whenHalThrowsException_fails() throws Exception { openAidlClients(/* numClients= */ 1); openAidlClients(/* numClients= */ 1); String exceptionMessage = "HAL service died."; String exceptionMessage = "HAL service died."; when(mBroadcastRadioMock.getImage(anyInt())) doThrow(new RemoteException(exceptionMessage)).when(mBroadcastRadioMock).getImage(anyInt()); .thenThrow(new RemoteException(exceptionMessage)); RuntimeException thrown = assertThrows(RuntimeException.class, () -> { RuntimeException thrown = assertThrows(RuntimeException.class, () -> { mTunerSessions[0].getImage(/* id= */ 1); mTunerSessions[0].getImage(/* id= */ 1); Loading @@ -654,7 +627,8 @@ public final class TunerSessionHidlTest extends ExtendedRadioMockitoTestCase { mTunerSessions[0].startBackgroundScan(); mTunerSessions[0].startBackgroundScan(); verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT.times(0)).onBackgroundScanComplete(); verify(mAidlTunerCallbackMocks[0], after(CALLBACK_TIMEOUT_MS).times(0)) .onBackgroundScanComplete(); } } @Test @Test Loading Loading @@ -845,8 +819,8 @@ public final class TunerSessionHidlTest extends ExtendedRadioMockitoTestCase { Map<String, String> parametersSet = Map.of("mockParam1", "mockValue1", Map<String, String> parametersSet = Map.of("mockParam1", "mockValue1", "mockParam2", "mockValue2"); "mockParam2", "mockValue2"); String exceptionMessage = "HAL service died."; String exceptionMessage = "HAL service died."; when(mHalTunerSessionMock.setParameters(any())) doThrow(new RemoteException(exceptionMessage)).when(mHalTunerSessionMock) .thenThrow(new RemoteException(exceptionMessage)); .setParameters(any()); RuntimeException thrown = assertThrows(RuntimeException.class, () -> { RuntimeException thrown = assertThrows(RuntimeException.class, () -> { mTunerSessions[0].setParameters(parametersSet); mTunerSessions[0].setParameters(parametersSet); Loading @@ -871,8 +845,8 @@ public final class TunerSessionHidlTest extends ExtendedRadioMockitoTestCase { openAidlClients(/* numClients= */ 1); openAidlClients(/* numClients= */ 1); List<String> parameterKeys = List.of("mockKey1", "mockKey2"); List<String> parameterKeys = List.of("mockKey1", "mockKey2"); String exceptionMessage = "HAL service died."; String exceptionMessage = "HAL service died."; when(mHalTunerSessionMock.getParameters(any())) doThrow(new RemoteException(exceptionMessage)).when(mHalTunerSessionMock) .thenThrow(new RemoteException(exceptionMessage)); .getParameters(any()); RuntimeException thrown = assertThrows(RuntimeException.class, () -> { RuntimeException thrown = assertThrows(RuntimeException.class, () -> { mTunerSessions[0].getParameters(parameterKeys); mTunerSessions[0].getParameters(parameterKeys); Loading @@ -883,7 +857,7 @@ public final class TunerSessionHidlTest extends ExtendedRadioMockitoTestCase { } } @Test @Test public void onCurrentProgramInfoChanged_withNoncurrentUser_doesNotInvokeCallback() public void onCurrentProgramInfoChanged_withNonCurrentUser_doesNotInvokeCallback() throws Exception { throws Exception { openAidlClients(1); openAidlClients(1); doReturn(USER_ID_2).when(() -> RadioServiceUserController.getCurrentUser()); doReturn(USER_ID_2).when(() -> RadioServiceUserController.getCurrentUser()); Loading @@ -891,7 +865,7 @@ public final class TunerSessionHidlTest extends ExtendedRadioMockitoTestCase { mHalTunerCallback.onCurrentProgramInfoChanged(TestUtils.makeHalProgramInfo( mHalTunerCallback.onCurrentProgramInfoChanged(TestUtils.makeHalProgramInfo( TestUtils.makeHalFmSelector(/* freq= */ 97300), SIGNAL_QUALITY)); TestUtils.makeHalFmSelector(/* freq= */ 97300), SIGNAL_QUALITY)); verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT.times(0)) verify(mAidlTunerCallbackMocks[0], after(CALLBACK_TIMEOUT_MS).times(0)) .onCurrentProgramInfoChanged(any()); .onCurrentProgramInfoChanged(any()); } } Loading Loading
core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/aidl/TunerSessionTest.java +33 −45 Original line number Original line Diff line number Diff line Loading @@ -16,20 +16,20 @@ package com.android.server.broadcastradio.aidl; package com.android.server.broadcastradio.aidl; import static com.android.dx.mockito.inline.extended.ExtendedMockito.after; import static com.android.dx.mockito.inline.extended.ExtendedMockito.any; import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyBoolean; import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyInt; import static com.android.dx.mockito.inline.extended.ExtendedMockito.doAnswer; import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; import static com.android.dx.mockito.inline.extended.ExtendedMockito.doThrow; import static com.android.dx.mockito.inline.extended.ExtendedMockito.eq; import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock; import static com.android.dx.mockito.inline.extended.ExtendedMockito.never; import static com.android.dx.mockito.inline.extended.ExtendedMockito.timeout; import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify; import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.app.compat.CompatChanges; import android.app.compat.CompatChanges; import android.graphics.Bitmap; import android.graphics.Bitmap; Loading Loading @@ -81,8 +81,8 @@ public final class TunerSessionTest extends ExtendedRadioMockitoTestCase { private static final int USER_ID_1 = 11; private static final int USER_ID_1 = 11; private static final int USER_ID_2 = 12; private static final int USER_ID_2 = 12; private static final VerificationWithTimeout CALLBACK_TIMEOUT = private static final int CALLBACK_TIMEOUT_MS = 200; timeout(/* millis= */ 200); private static final VerificationWithTimeout CALLBACK_TIMEOUT = timeout(CALLBACK_TIMEOUT_MS); private static final int SIGNAL_QUALITY = 90; private static final int SIGNAL_QUALITY = 90; private static final long AM_FM_FREQUENCY_SPACING = 500; private static final long AM_FM_FREQUENCY_SPACING = 500; private static final long[] AM_FM_FREQUENCY_LIST = {97_500, 98_100, 99_100}; private static final long[] AM_FM_FREQUENCY_LIST = {97_500, 98_100, 99_100}; Loading Loading @@ -166,12 +166,12 @@ public final class TunerSessionTest extends ExtendedRadioMockitoTestCase { @Before @Before public void setup() throws Exception { public void setup() throws Exception { when(mUserHandleMock.getIdentifier()).thenReturn(USER_ID_1); doReturn(true).when(() -> CompatChanges.isChangeEnabled( doReturn(true).when(() -> CompatChanges.isChangeEnabled( eq(ConversionUtils.RADIO_U_VERSION_REQUIRED), anyInt())); eq(ConversionUtils.RADIO_U_VERSION_REQUIRED), anyInt())); doReturn(USER_ID_1).when(mUserHandleMock).getIdentifier(); doReturn(mUserHandleMock).when(() -> Binder.getCallingUserHandle()); doReturn(true).when(() -> RadioServiceUserController.isCurrentOrSystemUser()); doReturn(true).when(() -> RadioServiceUserController.isCurrentOrSystemUser()); doReturn(USER_ID_1).when(() -> RadioServiceUserController.getCurrentUser()); doReturn(USER_ID_1).when(() -> RadioServiceUserController.getCurrentUser()); doReturn(mUserHandleMock).when(() -> Binder.getCallingUserHandle()); mRadioModule = new RadioModule(mBroadcastRadioMock, mRadioModule = new RadioModule(mBroadcastRadioMock, AidlTestUtils.makeDefaultModuleProperties()); AidlTestUtils.makeDefaultModuleProperties()); Loading Loading @@ -222,7 +222,7 @@ public final class TunerSessionTest extends ExtendedRadioMockitoTestCase { return Result.OK; return Result.OK; }).when(mBroadcastRadioMock).seek(anyBoolean(), anyBoolean()); }).when(mBroadcastRadioMock).seek(anyBoolean(), anyBoolean()); when(mBroadcastRadioMock.getImage(anyInt())).thenReturn(null); doReturn(null).when(mBroadcastRadioMock).getImage(anyInt()); doAnswer(invocation -> { doAnswer(invocation -> { int configFlag = (int) invocation.getArguments()[0]; int configFlag = (int) invocation.getArguments()[0]; Loading Loading @@ -275,7 +275,7 @@ public final class TunerSessionTest extends ExtendedRadioMockitoTestCase { mTunerSessions[0].setConfiguration(FM_BAND_CONFIG); mTunerSessions[0].setConfiguration(FM_BAND_CONFIG); verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT.times(0)) verify(mAidlTunerCallbackMocks[0], after(CALLBACK_TIMEOUT_MS).times(0)) .onConfigurationChanged(FM_BAND_CONFIG); .onConfigurationChanged(FM_BAND_CONFIG); } } Loading Loading @@ -446,25 +446,10 @@ public final class TunerSessionTest extends ExtendedRadioMockitoTestCase { mTunerSessions[0].tune(initialSel); mTunerSessions[0].tune(initialSel); verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT.times(0)) verify(mAidlTunerCallbackMocks[0], after(CALLBACK_TIMEOUT_MS).times(0)) .onCurrentProgramInfoChanged(tuneInfo); .onCurrentProgramInfoChanged(tuneInfo); } } @Test public void tune_forSystemUser() throws Exception { when(mUserHandleMock.getIdentifier()).thenReturn(UserHandle.USER_SYSTEM); doReturn(mUserHandleMock).when(() -> Binder.getCallingUserHandle()); doReturn(true).when(() -> RadioServiceUserController.isCurrentOrSystemUser()); ProgramSelector initialSel = AidlTestUtils.makeFmSelector(AM_FM_FREQUENCY_LIST[1]); RadioManager.ProgramInfo tuneInfo = AidlTestUtils.makeProgramInfo(initialSel, SIGNAL_QUALITY); openAidlClients(/* numClients= */ 1); mTunerSessions[0].tune(initialSel); verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT).onCurrentProgramInfoChanged(tuneInfo); } @Test @Test public void tune_withUnknownErrorFromHal_fails() throws Exception { public void tune_withUnknownErrorFromHal_fails() throws Exception { openAidlClients(/* numClients= */ 1); openAidlClients(/* numClients= */ 1); Loading Loading @@ -525,7 +510,7 @@ public final class TunerSessionTest extends ExtendedRadioMockitoTestCase { mTunerSessions[0].step(/* directionDown= */ true, /* skipSubChannel= */ false); mTunerSessions[0].step(/* directionDown= */ true, /* skipSubChannel= */ false); verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT.times(0)) verify(mAidlTunerCallbackMocks[0], after(CALLBACK_TIMEOUT_MS).times(0)) .onCurrentProgramInfoChanged(any()); .onCurrentProgramInfoChanged(any()); } } Loading Loading @@ -604,7 +589,7 @@ public final class TunerSessionTest extends ExtendedRadioMockitoTestCase { mTunerSessions[0].seek(/* directionDown= */ true, /* skipSubChannel= */ false); mTunerSessions[0].seek(/* directionDown= */ true, /* skipSubChannel= */ false); verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT.times(0)) verify(mAidlTunerCallbackMocks[0], after(CALLBACK_TIMEOUT_MS).times(0)) .onCurrentProgramInfoChanged(seekUpInfo); .onCurrentProgramInfoChanged(seekUpInfo); } } Loading Loading @@ -638,6 +623,7 @@ public final class TunerSessionTest extends ExtendedRadioMockitoTestCase { openAidlClients(/* numClients= */ 1); openAidlClients(/* numClients= */ 1); ProgramSelector initialSel = AidlTestUtils.makeFmSelector(AM_FM_FREQUENCY_LIST[1]); ProgramSelector initialSel = AidlTestUtils.makeFmSelector(AM_FM_FREQUENCY_LIST[1]); mTunerSessions[0].tune(initialSel); mTunerSessions[0].tune(initialSel); verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT).onCurrentProgramInfoChanged(any()); doReturn(false).when(() -> RadioServiceUserController.isCurrentOrSystemUser()); doReturn(false).when(() -> RadioServiceUserController.isCurrentOrSystemUser()); mTunerSessions[0].cancel(); mTunerSessions[0].cancel(); Loading Loading @@ -686,8 +672,8 @@ public final class TunerSessionTest extends ExtendedRadioMockitoTestCase { public void getImage_whenHalThrowsException_fails() throws Exception { public void getImage_whenHalThrowsException_fails() throws Exception { openAidlClients(/* numClients= */ 1); openAidlClients(/* numClients= */ 1); String exceptionMessage = "HAL service died."; String exceptionMessage = "HAL service died."; when(mBroadcastRadioMock.getImage(anyInt())) doThrow(new RemoteException(exceptionMessage)).when(mBroadcastRadioMock) .thenThrow(new RemoteException(exceptionMessage)); .getImage(anyInt()); RuntimeException thrown = assertThrows(RuntimeException.class, () -> { RuntimeException thrown = assertThrows(RuntimeException.class, () -> { mTunerSessions[0].getImage(/* id= */ 1); mTunerSessions[0].getImage(/* id= */ 1); Loading @@ -713,7 +699,8 @@ public final class TunerSessionTest extends ExtendedRadioMockitoTestCase { mTunerSessions[0].startBackgroundScan(); mTunerSessions[0].startBackgroundScan(); verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT.times(0)).onBackgroundScanComplete(); verify(mAidlTunerCallbackMocks[0], after(CALLBACK_TIMEOUT_MS).times(0)) .onBackgroundScanComplete(); } } @Test @Test Loading Loading @@ -905,7 +892,8 @@ public final class TunerSessionTest extends ExtendedRadioMockitoTestCase { mHalTunerCallback.onProgramListUpdated(AidlTestUtils.makeHalChunk(/* purge= */ false, mHalTunerCallback.onProgramListUpdated(AidlTestUtils.makeHalChunk(/* purge= */ false, /* complete= */ true, List.of(TEST_FM_INFO), new ArrayList<>())); /* complete= */ true, List.of(TEST_FM_INFO), new ArrayList<>())); verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT.times(0)).onProgramListUpdated(any()); verify(mAidlTunerCallbackMocks[0], after(CALLBACK_TIMEOUT_MS).times(0)) .onProgramListUpdated(any()); } } @Test @Test Loading Loading @@ -1160,8 +1148,8 @@ public final class TunerSessionTest extends ExtendedRadioMockitoTestCase { Map<String, String> parametersSet = Map.of("mockParam1", "mockValue1", Map<String, String> parametersSet = Map.of("mockParam1", "mockValue1", "mockParam2", "mockValue2"); "mockParam2", "mockValue2"); String exceptionMessage = "HAL service died."; String exceptionMessage = "HAL service died."; when(mBroadcastRadioMock.setParameters(any())) doThrow(new RemoteException(exceptionMessage)).when(mBroadcastRadioMock) .thenThrow(new RemoteException(exceptionMessage)); .setParameters(any()); RuntimeException thrown = assertThrows(RuntimeException.class, () -> { RuntimeException thrown = assertThrows(RuntimeException.class, () -> { mTunerSessions[0].setParameters(parametersSet); mTunerSessions[0].setParameters(parametersSet); Loading @@ -1186,8 +1174,8 @@ public final class TunerSessionTest extends ExtendedRadioMockitoTestCase { openAidlClients(/* numClients= */ 1); openAidlClients(/* numClients= */ 1); List<String> parameterKeys = List.of("mockKey1", "mockKey2"); List<String> parameterKeys = List.of("mockKey1", "mockKey2"); String exceptionMessage = "HAL service died."; String exceptionMessage = "HAL service died."; when(mBroadcastRadioMock.getParameters(any())) doThrow(new RemoteException(exceptionMessage)).when(mBroadcastRadioMock) .thenThrow(new RemoteException(exceptionMessage)); .getParameters(any()); RuntimeException thrown = assertThrows(RuntimeException.class, () -> { RuntimeException thrown = assertThrows(RuntimeException.class, () -> { mTunerSessions[0].getParameters(parameterKeys); mTunerSessions[0].getParameters(parameterKeys); Loading @@ -1198,7 +1186,7 @@ public final class TunerSessionTest extends ExtendedRadioMockitoTestCase { } } @Test @Test public void onCurrentProgramInfoChanged_withNoncurrentUser_doesNotInvokeCallback() public void onCurrentProgramInfoChanged_withNonCurrentUser_doesNotInvokeCallback() throws Exception { throws Exception { openAidlClients(1); openAidlClients(1); doReturn(USER_ID_2).when(() -> RadioServiceUserController.getCurrentUser()); doReturn(USER_ID_2).when(() -> RadioServiceUserController.getCurrentUser()); Loading @@ -1206,7 +1194,7 @@ public final class TunerSessionTest extends ExtendedRadioMockitoTestCase { mHalTunerCallback.onCurrentProgramInfoChanged(AidlTestUtils.makeHalProgramInfo( mHalTunerCallback.onCurrentProgramInfoChanged(AidlTestUtils.makeHalProgramInfo( AidlTestUtils.makeHalFmSelector(AM_FM_FREQUENCY_LIST[1]), SIGNAL_QUALITY)); AidlTestUtils.makeHalFmSelector(AM_FM_FREQUENCY_LIST[1]), SIGNAL_QUALITY)); verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT.times(0)) verify(mAidlTunerCallbackMocks[0], after(CALLBACK_TIMEOUT_MS).times(0)) .onCurrentProgramInfoChanged(any()); .onCurrentProgramInfoChanged(any()); } } Loading
core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/hal2/TunerSessionHidlTest.java +28 −54 Original line number Original line Diff line number Diff line Loading @@ -16,22 +16,22 @@ package com.android.server.broadcastradio.hal2; package com.android.server.broadcastradio.hal2; import static com.android.dx.mockito.inline.extended.ExtendedMockito.after; import static com.android.dx.mockito.inline.extended.ExtendedMockito.any; import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyBoolean; import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyInt; import static com.android.dx.mockito.inline.extended.ExtendedMockito.doAnswer; import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; import static com.android.dx.mockito.inline.extended.ExtendedMockito.doThrow; import static com.android.dx.mockito.inline.extended.ExtendedMockito.eq; import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock; import static com.android.dx.mockito.inline.extended.ExtendedMockito.never; import static com.android.dx.mockito.inline.extended.ExtendedMockito.timeout; import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify; import static com.google.common.truth.Truth.assertWithMessage; import static com.google.common.truth.Truth.assertWithMessage; import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.graphics.Bitmap; import android.graphics.Bitmap; import android.hardware.broadcastradio.V2_0.Constants; import android.hardware.broadcastradio.V2_0.Constants; Loading Loading @@ -78,8 +78,8 @@ public final class TunerSessionHidlTest extends ExtendedRadioMockitoTestCase { private static final int USER_ID_1 = 11; private static final int USER_ID_1 = 11; private static final int USER_ID_2 = 12; private static final int USER_ID_2 = 12; private static final VerificationWithTimeout CALLBACK_TIMEOUT = private static final int CALLBACK_TIMEOUT_MS = 200; timeout(/* millis= */ 200); private static final VerificationWithTimeout CALLBACK_TIMEOUT = timeout(CALLBACK_TIMEOUT_MS); private static final int SIGNAL_QUALITY = 1; private static final int SIGNAL_QUALITY = 1; private static final long AM_FM_FREQUENCY_SPACING = 500; private static final long AM_FM_FREQUENCY_SPACING = 500; private static final long[] AM_FM_FREQUENCY_LIST = {97_500, 98_100, 99_100}; private static final long[] AM_FM_FREQUENCY_LIST = {97_500, 98_100, 99_100}; Loading Loading @@ -113,7 +113,7 @@ public final class TunerSessionHidlTest extends ExtendedRadioMockitoTestCase { @Before @Before public void setup() throws Exception { public void setup() throws Exception { when(mUserHandleMock.getIdentifier()).thenReturn(USER_ID_1); doReturn(USER_ID_1).when(mUserHandleMock).getIdentifier(); doReturn(mUserHandleMock).when(() -> Binder.getCallingUserHandle()); doReturn(mUserHandleMock).when(() -> Binder.getCallingUserHandle()); doReturn(true).when(() -> RadioServiceUserController.isCurrentOrSystemUser()); doReturn(true).when(() -> RadioServiceUserController.isCurrentOrSystemUser()); doReturn(USER_ID_1).when(() -> RadioServiceUserController.getCurrentUser()); doReturn(USER_ID_1).when(() -> RadioServiceUserController.getCurrentUser()); Loading Loading @@ -170,7 +170,7 @@ public final class TunerSessionHidlTest extends ExtendedRadioMockitoTestCase { return Result.OK; return Result.OK; }).when(mHalTunerSessionMock).scan(anyBoolean(), anyBoolean()); }).when(mHalTunerSessionMock).scan(anyBoolean(), anyBoolean()); when(mBroadcastRadioMock.getImage(anyInt())).thenReturn(new ArrayList<Byte>(0)); doReturn(new ArrayList<Byte>(0)).when(mBroadcastRadioMock).getImage(anyInt()); doAnswer(invocation -> { doAnswer(invocation -> { int configFlag = (int) invocation.getArguments()[0]; int configFlag = (int) invocation.getArguments()[0]; Loading Loading @@ -227,7 +227,7 @@ public final class TunerSessionHidlTest extends ExtendedRadioMockitoTestCase { mTunerSessions[0].setConfiguration(FM_BAND_CONFIG); mTunerSessions[0].setConfiguration(FM_BAND_CONFIG); verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT.times(0)) verify(mAidlTunerCallbackMocks[0], after(CALLBACK_TIMEOUT_MS).times(0)) .onConfigurationChanged(FM_BAND_CONFIG); .onConfigurationChanged(FM_BAND_CONFIG); } } Loading Loading @@ -379,7 +379,7 @@ public final class TunerSessionHidlTest extends ExtendedRadioMockitoTestCase { mTunerSessions[0].tune(initialSel); mTunerSessions[0].tune(initialSel); verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT.times(0)) verify(mAidlTunerCallbackMocks[0], after(CALLBACK_TIMEOUT_MS).times(0)) .onCurrentProgramInfoChanged(tuneInfo); .onCurrentProgramInfoChanged(tuneInfo); } } Loading @@ -397,20 +397,6 @@ public final class TunerSessionHidlTest extends ExtendedRadioMockitoTestCase { .that(thrown).hasMessageThat().contains(Result.toString(Result.UNKNOWN_ERROR)); .that(thrown).hasMessageThat().contains(Result.toString(Result.UNKNOWN_ERROR)); } } @Test public void tune_forSystemUser() throws Exception { when(mUserHandleMock.getIdentifier()).thenReturn(UserHandle.USER_SYSTEM); doReturn(mUserHandleMock).when(() -> Binder.getCallingUserHandle()); doReturn(true).when(() -> RadioServiceUserController.isCurrentOrSystemUser()); ProgramSelector initialSel = TestUtils.makeFmSelector(AM_FM_FREQUENCY_LIST[1]); RadioManager.ProgramInfo tuneInfo = TestUtils.makeProgramInfo(initialSel, SIGNAL_QUALITY); openAidlClients(/* numClients= */ 1); mTunerSessions[0].tune(initialSel); verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT).onCurrentProgramInfoChanged(tuneInfo); } @Test @Test public void step_withDirectionUp() throws Exception { public void step_withDirectionUp() throws Exception { long initFreq = AM_FM_FREQUENCY_LIST[1]; long initFreq = AM_FM_FREQUENCY_LIST[1]; Loading Loading @@ -455,7 +441,7 @@ public final class TunerSessionHidlTest extends ExtendedRadioMockitoTestCase { mTunerSessions[0].step(/* directionDown= */ true, /* skipSubChannel= */ false); mTunerSessions[0].step(/* directionDown= */ true, /* skipSubChannel= */ false); verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT.times(0)) verify(mAidlTunerCallbackMocks[0], after(CALLBACK_TIMEOUT_MS).times(0)) .onCurrentProgramInfoChanged(any()); .onCurrentProgramInfoChanged(any()); } } Loading Loading @@ -533,7 +519,7 @@ public final class TunerSessionHidlTest extends ExtendedRadioMockitoTestCase { mTunerSessions[0].seek(/* directionDown= */ true, /* skipSubChannel= */ false); mTunerSessions[0].seek(/* directionDown= */ true, /* skipSubChannel= */ false); verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT.times(0)) verify(mAidlTunerCallbackMocks[0], after(CALLBACK_TIMEOUT_MS).times(0)) .onCurrentProgramInfoChanged(seekUpInfo); .onCurrentProgramInfoChanged(seekUpInfo); } } Loading Loading @@ -562,18 +548,6 @@ public final class TunerSessionHidlTest extends ExtendedRadioMockitoTestCase { verify(mHalTunerSessionMock).cancel(); verify(mHalTunerSessionMock).cancel(); } } @Test public void cancel_forNonCurrentUser() throws Exception { openAidlClients(/* numClients= */ 1); ProgramSelector initialSel = TestUtils.makeFmSelector(AM_FM_FREQUENCY_LIST[1]); mTunerSessions[0].tune(initialSel); doReturn(false).when(() -> RadioServiceUserController.isCurrentOrSystemUser()); mTunerSessions[0].cancel(); verify(mHalTunerSessionMock, never()).cancel(); } @Test @Test public void cancel_forNonCurrentUser_doesNotCancel() throws Exception { public void cancel_forNonCurrentUser_doesNotCancel() throws Exception { openAidlClients(/* numClients= */ 1); openAidlClients(/* numClients= */ 1); Loading Loading @@ -627,8 +601,7 @@ public final class TunerSessionHidlTest extends ExtendedRadioMockitoTestCase { public void getImage_whenHalThrowsException_fails() throws Exception { public void getImage_whenHalThrowsException_fails() throws Exception { openAidlClients(/* numClients= */ 1); openAidlClients(/* numClients= */ 1); String exceptionMessage = "HAL service died."; String exceptionMessage = "HAL service died."; when(mBroadcastRadioMock.getImage(anyInt())) doThrow(new RemoteException(exceptionMessage)).when(mBroadcastRadioMock).getImage(anyInt()); .thenThrow(new RemoteException(exceptionMessage)); RuntimeException thrown = assertThrows(RuntimeException.class, () -> { RuntimeException thrown = assertThrows(RuntimeException.class, () -> { mTunerSessions[0].getImage(/* id= */ 1); mTunerSessions[0].getImage(/* id= */ 1); Loading @@ -654,7 +627,8 @@ public final class TunerSessionHidlTest extends ExtendedRadioMockitoTestCase { mTunerSessions[0].startBackgroundScan(); mTunerSessions[0].startBackgroundScan(); verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT.times(0)).onBackgroundScanComplete(); verify(mAidlTunerCallbackMocks[0], after(CALLBACK_TIMEOUT_MS).times(0)) .onBackgroundScanComplete(); } } @Test @Test Loading Loading @@ -845,8 +819,8 @@ public final class TunerSessionHidlTest extends ExtendedRadioMockitoTestCase { Map<String, String> parametersSet = Map.of("mockParam1", "mockValue1", Map<String, String> parametersSet = Map.of("mockParam1", "mockValue1", "mockParam2", "mockValue2"); "mockParam2", "mockValue2"); String exceptionMessage = "HAL service died."; String exceptionMessage = "HAL service died."; when(mHalTunerSessionMock.setParameters(any())) doThrow(new RemoteException(exceptionMessage)).when(mHalTunerSessionMock) .thenThrow(new RemoteException(exceptionMessage)); .setParameters(any()); RuntimeException thrown = assertThrows(RuntimeException.class, () -> { RuntimeException thrown = assertThrows(RuntimeException.class, () -> { mTunerSessions[0].setParameters(parametersSet); mTunerSessions[0].setParameters(parametersSet); Loading @@ -871,8 +845,8 @@ public final class TunerSessionHidlTest extends ExtendedRadioMockitoTestCase { openAidlClients(/* numClients= */ 1); openAidlClients(/* numClients= */ 1); List<String> parameterKeys = List.of("mockKey1", "mockKey2"); List<String> parameterKeys = List.of("mockKey1", "mockKey2"); String exceptionMessage = "HAL service died."; String exceptionMessage = "HAL service died."; when(mHalTunerSessionMock.getParameters(any())) doThrow(new RemoteException(exceptionMessage)).when(mHalTunerSessionMock) .thenThrow(new RemoteException(exceptionMessage)); .getParameters(any()); RuntimeException thrown = assertThrows(RuntimeException.class, () -> { RuntimeException thrown = assertThrows(RuntimeException.class, () -> { mTunerSessions[0].getParameters(parameterKeys); mTunerSessions[0].getParameters(parameterKeys); Loading @@ -883,7 +857,7 @@ public final class TunerSessionHidlTest extends ExtendedRadioMockitoTestCase { } } @Test @Test public void onCurrentProgramInfoChanged_withNoncurrentUser_doesNotInvokeCallback() public void onCurrentProgramInfoChanged_withNonCurrentUser_doesNotInvokeCallback() throws Exception { throws Exception { openAidlClients(1); openAidlClients(1); doReturn(USER_ID_2).when(() -> RadioServiceUserController.getCurrentUser()); doReturn(USER_ID_2).when(() -> RadioServiceUserController.getCurrentUser()); Loading @@ -891,7 +865,7 @@ public final class TunerSessionHidlTest extends ExtendedRadioMockitoTestCase { mHalTunerCallback.onCurrentProgramInfoChanged(TestUtils.makeHalProgramInfo( mHalTunerCallback.onCurrentProgramInfoChanged(TestUtils.makeHalProgramInfo( TestUtils.makeHalFmSelector(/* freq= */ 97300), SIGNAL_QUALITY)); TestUtils.makeHalFmSelector(/* freq= */ 97300), SIGNAL_QUALITY)); verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT.times(0)) verify(mAidlTunerCallbackMocks[0], after(CALLBACK_TIMEOUT_MS).times(0)) .onCurrentProgramInfoChanged(any()); .onCurrentProgramInfoChanged(any()); } } Loading