Merge "Fix result mismatch in broadcast radio service" into udc-dev

This commit is contained in:
Treehugger Robot
2023-04-26 23:53:22 +00:00
committed by Android (Google) Code Review
5 changed files with 35 additions and 2 deletions

View File

@@ -80,7 +80,7 @@ final class AidlTestUtils {
/* vendorIds= */ null);
}
static android.hardware.broadcastradio.ProgramSelector makeHalFmSelector(int freq) {
static android.hardware.broadcastradio.ProgramSelector makeHalFmSelector(long freq) {
ProgramIdentifier halId = makeHalIdentifier(IdentifierType.AMFM_FREQUENCY_KHZ, freq);
return makeHalSelector(halId, /* secondaryIds= */ new ProgramIdentifier[0]);
}

View File

@@ -52,6 +52,7 @@ public final class ConversionUtilsResultTest {
{Result.INVALID_STATE, RadioTuner.TUNER_RESULT_INVALID_STATE},
{Result.NOT_SUPPORTED, RadioTuner.TUNER_RESULT_NOT_SUPPORTED},
{Result.TIMEOUT, RadioTuner.TUNER_RESULT_TIMEOUT},
{Result.CANCELED, RadioTuner.TUNER_RESULT_CANCELED},
{Result.UNKNOWN_ERROR, RadioTuner.TUNER_RESULT_UNKNOWN_ERROR}
});
}

View File

@@ -27,11 +27,13 @@ import android.hardware.broadcastradio.ProgramIdentifier;
import android.hardware.broadcastradio.ProgramInfo;
import android.hardware.broadcastradio.ProgramListChunk;
import android.hardware.broadcastradio.Properties;
import android.hardware.broadcastradio.Result;
import android.hardware.broadcastradio.VendorKeyValue;
import android.hardware.radio.Announcement;
import android.hardware.radio.ProgramList;
import android.hardware.radio.ProgramSelector;
import android.hardware.radio.RadioManager;
import android.os.ServiceSpecificException;
import com.android.dx.mockito.inline.extended.StaticMockitoSessionBuilder;
import com.android.server.broadcastradio.ExtendedRadioMockitoTestCase;
@@ -152,6 +154,16 @@ public final class ConversionUtilsTest extends ExtendedRadioMockitoTestCase {
.that(ConversionUtils.isAtLeastU(U_APP_UID)).isTrue();
}
@Test
public void throwOnError_withCancelException() {
ServiceSpecificException halException = new ServiceSpecificException(Result.CANCELED);
RuntimeException thrown = ConversionUtils.throwOnError(halException, "tune");
expect.withMessage("Exception thrown for canceling error").that(thrown)
.hasMessageThat().contains("tune: CANCELED");
}
@Test
public void propertiesFromHalProperties_idsMatch() {
expect.withMessage("Properties id")

View File

@@ -1168,12 +1168,28 @@ public final class TunerSessionTest extends ExtendedRadioMockitoTestCase {
doReturn(USER_ID_2).when(() -> RadioServiceUserController.getCurrentUser());
mHalTunerCallback.onCurrentProgramInfoChanged(AidlTestUtils.makeHalProgramInfo(
AidlTestUtils.makeHalFmSelector(/* freq= */ 97300), SIGNAL_QUALITY));
AidlTestUtils.makeHalFmSelector(AM_FM_FREQUENCY_LIST[1]), SIGNAL_QUALITY));
verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT.times(0))
.onCurrentProgramInfoChanged(any());
}
@Test
public void onTuneFailed_forTunerCallback() throws Exception {
int numSessions = 3;
openAidlClients(numSessions);
android.hardware.broadcastradio.ProgramSelector halSel = AidlTestUtils.makeHalFmSelector(
AM_FM_FREQUENCY_LIST[1]);
ProgramSelector sel = AidlTestUtils.makeFmSelector(AM_FM_FREQUENCY_LIST[1]);
mHalTunerCallback.onTuneFailed(Result.CANCELED, halSel);
for (int index = 0; index < numSessions; index++) {
verify(mAidlTunerCallbackMocks[index], CALLBACK_TIMEOUT)
.onTuneFailed(RadioTuner.TUNER_RESULT_CANCELED, sel);
}
}
@Test
public void onAntennaStateChange_forTunerCallback() throws Exception {
int numSessions = 3;

View File

@@ -102,6 +102,8 @@ final class ConversionUtils {
return new UnsupportedOperationException(action + ": NOT_SUPPORTED");
case Result.TIMEOUT:
return new ParcelableException(new RuntimeException(action + ": TIMEOUT"));
case Result.CANCELED:
return new IllegalStateException(action + ": CANCELED");
default:
return new ParcelableException(new RuntimeException(
action + ": unknown error (" + result + ")"));
@@ -123,6 +125,8 @@ final class ConversionUtils {
return RadioTuner.TUNER_RESULT_NOT_SUPPORTED;
case Result.TIMEOUT:
return RadioTuner.TUNER_RESULT_TIMEOUT;
case Result.CANCELED:
return RadioTuner.TUNER_RESULT_CANCELED;
case Result.UNKNOWN_ERROR:
default:
return RadioTuner.TUNER_RESULT_UNKNOWN_ERROR;