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

Commit 567deade authored by Weilin Xu's avatar Weilin Xu
Browse files

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
parent c0b7cdc4
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -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
+65 −0
Original line number Diff line number Diff line
/*
 * 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);
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -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());
        }
    }

+66 −0
Original line number Diff line number Diff line
/*
 * 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);
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -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());
        }
    }

Loading