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

Commit 1aaea81f authored by Weilin Xu's avatar Weilin Xu
Browse files

Fix result mismatch in broadcast radio service

Fixed the issue that canceling result is handled as unknown error
in broadcast radio service for AIDL HAL.

Bug: 279673227
Test: atest com.android.server.broadcastradio.aidl
Change-Id: I1908943ef10737db2441a555d9da97e0d02ac908
parent a3467673
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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]);
    }
+1 −0
Original line number Diff line number Diff line
@@ -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}
        });
    }
+12 −0
Original line number Diff line number Diff line
@@ -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")
+17 −1
Original line number Diff line number Diff line
@@ -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;
+4 −0
Original line number Diff line number Diff line
@@ -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;