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

Commit 284f7be4 authored by Weilin Xu's avatar Weilin Xu
Browse files

Handle remote exception for bcradio openSession

Added logic to return null when AIDL broadcast radio HAL client opens
a session, but broadcast radio HAL throws remote exception during
setting tuner callback.

Bug: 358467578
Flag: EXEMPT bugfix
Test: atest com.android.server.broadcastradio.aidl.TunerSessionTest
Change-Id: I1886bb3fbbd5a46b29761a7deba334bae4dca3c0
parent bcbae012
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -73,6 +73,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.verification.VerificationWithTimeout;

import java.util.ArrayList;
@@ -212,6 +213,18 @@ public final class TunerSessionTest extends ExtendedRadioMockitoTestCase {
        }
    }

    @Test
    public void openSession_whenHalThrowsRemoteException() throws Exception {
        android.hardware.radio.ITunerCallback tunerCallbackMock =
                mock(android.hardware.radio.ITunerCallback.class);
        Mockito.doThrow(new RemoteException("HAL service died")).when(mBroadcastRadioMock)
                .setTunerCallback(any());

        expect.withMessage("Null tuner session with HAL throwing remote exception")
                .that(mRadioModule.openSession(tunerCallbackMock)).isNull();

    }

    @Test
    public void setConfiguration() throws Exception {
        openAidlClients(/* numClients= */ 1);
+1 −1
Original line number Diff line number Diff line
@@ -222,7 +222,7 @@ public final class BroadcastRadioServiceImpl {
        }

        TunerSession tunerSession = radioModule.openSession(callback);
        if (legacyConfig != null) {
        if (tunerSession != null && legacyConfig != null) {
            tunerSession.setConfiguration(legacyConfig);
        }
        return tunerSession;
+8 −1
Original line number Diff line number Diff line
@@ -247,6 +247,7 @@ final class RadioModule {
        return mProperties;
    }

    @Nullable
    TunerSession openSession(android.hardware.radio.ITunerCallback userCb)
            throws RemoteException {
        mLogger.logRadioEvent("Open TunerSession");
@@ -260,7 +261,13 @@ final class RadioModule {
            antennaConnected = mAntennaConnected;
            currentProgramInfo = mCurrentProgramInfo;
            if (isFirstTunerSession) {
                try {
                    mService.setTunerCallback(mHalTunerCallback);
                } catch (RemoteException ex) {
                    Slogf.wtf(TAG, ex, "Failed to register HAL callback for module %d",
                            mProperties.getId());
                    return null;
                }
            }
        }
        // Propagate state to new client.