Implement explicit result conversion for radio HAL
Explicit broadcast radio HAL result conversion was implemented so that the order of definition for result enum in HAL does not have to be the same as TunerResultType in RadioTuner. Parameterized tests were also added for this result conversion. Bug: 257337458 Test: atest com.android.server.broadcastradio Test: atest android.hardware.radio.tests.unittests Change-Id: Ia41020e01b0727eea612470bae32810fb8b1cc58
This commit is contained in:
@@ -98,7 +98,7 @@ public final class TunerAdapterTest {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
if (program.getPrimaryId().getValue() < AM_LOWER_LIMIT_KHZ) {
|
||||
mTunerCallback.onTuneFailed(RadioManager.STATUS_BAD_VALUE, program);
|
||||
mTunerCallback.onTuneFailed(RadioTuner.TUNER_RESULT_INVALID_ARGUMENTS, program);
|
||||
} else {
|
||||
mTunerCallback.onCurrentProgramInfoChanged(FM_PROGRAM_INFO);
|
||||
}
|
||||
@@ -208,14 +208,14 @@ public final class TunerAdapterTest {
|
||||
@Test
|
||||
public void seek_forTunerAdapter_invokesOnErrorWhenTimeout() throws Exception {
|
||||
doAnswer(invocation -> {
|
||||
mTunerCallback.onTuneFailed(RadioManager.STATUS_TIMED_OUT, FM_SELECTOR);
|
||||
mTunerCallback.onTuneFailed(RadioTuner.TUNER_RESULT_TIMEOUT, FM_SELECTOR);
|
||||
return RadioManager.STATUS_OK;
|
||||
}).when(mTunerMock).seek(anyBoolean(), anyBoolean());
|
||||
|
||||
mRadioTuner.scan(RadioTuner.DIRECTION_UP, /* skipSubChannel*/ true);
|
||||
|
||||
verify(mCallbackMock, timeout(CALLBACK_TIMEOUT_MS)).onTuneFailed(
|
||||
RadioManager.STATUS_TIMED_OUT, FM_SELECTOR);
|
||||
RadioTuner.TUNER_RESULT_TIMEOUT, FM_SELECTOR);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -246,7 +246,7 @@ public final class TunerAdapterTest {
|
||||
mRadioTuner.tune(invalidSelector);
|
||||
|
||||
verify(mCallbackMock, timeout(CALLBACK_TIMEOUT_MS))
|
||||
.onTuneFailed(RadioManager.STATUS_BAD_VALUE, invalidSelector);
|
||||
.onTuneFailed(RadioTuner.TUNER_RESULT_INVALID_ARGUMENTS, invalidSelector);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.server.broadcastradio.aidl;
|
||||
|
||||
import android.hardware.broadcastradio.Result;
|
||||
import android.hardware.radio.RadioTuner;
|
||||
|
||||
import com.google.common.truth.Expect;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public final class ConversionUtilsResultTest {
|
||||
|
||||
private final int mHalResult;
|
||||
private final int mTunerResult;
|
||||
|
||||
@Rule
|
||||
public final Expect expect = Expect.create();
|
||||
|
||||
public ConversionUtilsResultTest(int halResult, int tunerResult) {
|
||||
this.mHalResult = halResult;
|
||||
this.mTunerResult = tunerResult;
|
||||
}
|
||||
|
||||
@Parameterized.Parameters
|
||||
public static List<Object[]> inputParameters() {
|
||||
return Arrays.asList(new Object[][]{
|
||||
{Result.OK, RadioTuner.TUNER_RESULT_OK},
|
||||
{Result.INTERNAL_ERROR, RadioTuner.TUNER_RESULT_INTERNAL_ERROR},
|
||||
{Result.INVALID_ARGUMENTS, RadioTuner.TUNER_RESULT_INVALID_ARGUMENTS},
|
||||
{Result.INVALID_STATE, RadioTuner.TUNER_RESULT_INVALID_STATE},
|
||||
{Result.NOT_SUPPORTED, RadioTuner.TUNER_RESULT_NOT_SUPPORTED},
|
||||
{Result.TIMEOUT, RadioTuner.TUNER_RESULT_TIMEOUT},
|
||||
{Result.UNKNOWN_ERROR, RadioTuner.TUNER_RESULT_UNKNOWN_ERROR}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void halResultToTunerResult() {
|
||||
expect.withMessage("Tuner result converted from AIDL HAL result %s", mHalResult)
|
||||
.that(ConversionUtils.halResultToTunerResult(mHalResult))
|
||||
.isEqualTo(mTunerResult);
|
||||
}
|
||||
}
|
||||
@@ -416,7 +416,7 @@ public final class TunerSessionTest extends ExtendedRadioMockitoTestCase {
|
||||
|
||||
for (int index = 0; index < numSessions; index++) {
|
||||
verify(mAidlTunerCallbackMocks[index], CALLBACK_TIMEOUT)
|
||||
.onTuneFailed(eq(Result.TIMEOUT), any());
|
||||
.onTuneFailed(eq(RadioTuner.TUNER_RESULT_TIMEOUT), any());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.server.broadcastradio.hal2;
|
||||
|
||||
import android.hardware.broadcastradio.V2_0.Result;
|
||||
import android.hardware.radio.RadioTuner;
|
||||
|
||||
import com.google.common.truth.Expect;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public final class ConvertResultTest {
|
||||
|
||||
private final int mHalResult;
|
||||
private final int mTunerResult;
|
||||
|
||||
@Rule
|
||||
public final Expect expect = Expect.create();
|
||||
|
||||
public ConvertResultTest(int halResult, int tunerResult) {
|
||||
this.mHalResult = halResult;
|
||||
this.mTunerResult = tunerResult;
|
||||
}
|
||||
|
||||
@Parameterized.Parameters
|
||||
public static List<Object[]> inputParameters() {
|
||||
return Arrays.asList(new Object[][]{
|
||||
{Result.OK, RadioTuner.TUNER_RESULT_OK},
|
||||
{Result.INTERNAL_ERROR, RadioTuner.TUNER_RESULT_INTERNAL_ERROR},
|
||||
{Result.INVALID_ARGUMENTS, RadioTuner.TUNER_RESULT_INVALID_ARGUMENTS},
|
||||
{Result.INVALID_STATE, RadioTuner.TUNER_RESULT_INVALID_STATE},
|
||||
{Result.NOT_SUPPORTED, RadioTuner.TUNER_RESULT_NOT_SUPPORTED},
|
||||
{Result.TIMEOUT, RadioTuner.TUNER_RESULT_TIMEOUT},
|
||||
{Result.UNKNOWN_ERROR, RadioTuner.TUNER_RESULT_UNKNOWN_ERROR}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void halResultToTunerResult() {
|
||||
expect.withMessage("Tuner result converted from HAL 2.0 result %s",
|
||||
Result.toString(mHalResult))
|
||||
.that(Convert.halResultToTunerResult(mHalResult))
|
||||
.isEqualTo(mTunerResult);
|
||||
}
|
||||
}
|
||||
@@ -409,7 +409,7 @@ public final class TunerSessionHidlTest extends ExtendedRadioMockitoTestCase {
|
||||
|
||||
for (int index = 0; index < numSessions; index++) {
|
||||
verify(mAidlTunerCallbackMocks[index], CALLBACK_TIMEOUT)
|
||||
.onTuneFailed(eq(Result.TIMEOUT), any());
|
||||
.onTuneFailed(eq(RadioTuner.TUNER_RESULT_TIMEOUT), any());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ import android.hardware.radio.ProgramList;
|
||||
import android.hardware.radio.ProgramSelector;
|
||||
import android.hardware.radio.RadioManager;
|
||||
import android.hardware.radio.RadioMetadata;
|
||||
import android.hardware.radio.RadioTuner;
|
||||
import android.os.Build;
|
||||
import android.os.ParcelableException;
|
||||
import android.os.ServiceSpecificException;
|
||||
@@ -95,6 +96,27 @@ final class ConversionUtils {
|
||||
}
|
||||
}
|
||||
|
||||
@RadioTuner.TunerResultType
|
||||
static int halResultToTunerResult(int result) {
|
||||
switch (result) {
|
||||
case Result.OK:
|
||||
return RadioTuner.TUNER_RESULT_OK;
|
||||
case Result.INTERNAL_ERROR:
|
||||
return RadioTuner.TUNER_RESULT_INTERNAL_ERROR;
|
||||
case Result.INVALID_ARGUMENTS:
|
||||
return RadioTuner.TUNER_RESULT_INVALID_ARGUMENTS;
|
||||
case Result.INVALID_STATE:
|
||||
return RadioTuner.TUNER_RESULT_INVALID_STATE;
|
||||
case Result.NOT_SUPPORTED:
|
||||
return RadioTuner.TUNER_RESULT_NOT_SUPPORTED;
|
||||
case Result.TIMEOUT:
|
||||
return RadioTuner.TUNER_RESULT_TIMEOUT;
|
||||
case Result.UNKNOWN_ERROR:
|
||||
default:
|
||||
return RadioTuner.TUNER_RESULT_UNKNOWN_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
static VendorKeyValue[] vendorInfoToHalVendorKeyValues(@Nullable Map<String, String> info) {
|
||||
if (info == null) {
|
||||
return new VendorKeyValue[]{};
|
||||
|
||||
@@ -100,6 +100,7 @@ final class RadioModule {
|
||||
synchronized (mLock) {
|
||||
android.hardware.radio.ProgramSelector csel =
|
||||
ConversionUtils.programSelectorFromHalProgramSelector(programSelector);
|
||||
int tunerResult = ConversionUtils.halResultToTunerResult(result);
|
||||
fanoutAidlCallbackLocked((cb, sdkVersion) -> {
|
||||
if (csel != null && !ConversionUtils
|
||||
.programSelectorMeetsSdkVersionRequirement(csel, sdkVersion)) {
|
||||
@@ -107,7 +108,7 @@ final class RadioModule {
|
||||
+ "requiring higher target SDK version");
|
||||
return;
|
||||
}
|
||||
cb.onTuneFailed(result, csel);
|
||||
cb.onTuneFailed(tunerResult, csel);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -36,6 +36,7 @@ import android.hardware.radio.ProgramList;
|
||||
import android.hardware.radio.ProgramSelector;
|
||||
import android.hardware.radio.RadioManager;
|
||||
import android.hardware.radio.RadioMetadata;
|
||||
import android.hardware.radio.RadioTuner;
|
||||
import android.os.ParcelableException;
|
||||
import android.util.Slog;
|
||||
|
||||
@@ -81,6 +82,27 @@ class Convert {
|
||||
}
|
||||
}
|
||||
|
||||
@RadioTuner.TunerResultType
|
||||
static int halResultToTunerResult(int result) {
|
||||
switch (result) {
|
||||
case Result.OK:
|
||||
return RadioTuner.TUNER_RESULT_OK;
|
||||
case Result.INTERNAL_ERROR:
|
||||
return RadioTuner.TUNER_RESULT_INTERNAL_ERROR;
|
||||
case Result.INVALID_ARGUMENTS:
|
||||
return RadioTuner.TUNER_RESULT_INVALID_ARGUMENTS;
|
||||
case Result.INVALID_STATE:
|
||||
return RadioTuner.TUNER_RESULT_INVALID_STATE;
|
||||
case Result.NOT_SUPPORTED:
|
||||
return RadioTuner.TUNER_RESULT_NOT_SUPPORTED;
|
||||
case Result.TIMEOUT:
|
||||
return RadioTuner.TUNER_RESULT_TIMEOUT;
|
||||
case Result.UNKNOWN_ERROR:
|
||||
default:
|
||||
return RadioTuner.TUNER_RESULT_UNKNOWN_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
static @NonNull ArrayList<VendorKeyValue>
|
||||
vendorInfoToHal(@Nullable Map<String, String> info) {
|
||||
if (info == null) return new ArrayList<>();
|
||||
|
||||
@@ -87,8 +87,9 @@ final class RadioModule {
|
||||
fireLater(() -> {
|
||||
android.hardware.radio.ProgramSelector csel =
|
||||
Convert.programSelectorFromHal(programSelector);
|
||||
int tunerResult = Convert.halResultToTunerResult(result);
|
||||
synchronized (mLock) {
|
||||
fanoutAidlCallbackLocked(cb -> cb.onTuneFailed(result, csel));
|
||||
fanoutAidlCallbackLocked(cb -> cb.onTuneFailed(tunerResult, csel));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user