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

Commit 21da4838 authored by Weilin Xu's avatar Weilin Xu
Browse files

Use CompatChanges to radio app version check

Instead of comparing SDK version of application directly in broadcast
radio service, used CompatChanges methods with UID of application, to
check whether it meets the SDK version requirement for program info
and program list from broadcast radio HAL.

Bug: 261770108
Test: atest android.hardware.radio
Test: atest com.android.server.broadcastradio.aidl
Change-Id: I7fe6d22bdb80a654cdd918114ff26d7faaf2e879
parent 99e93940
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ interface IRadioService {
    List<RadioManager.ModuleProperties> listModules();

    ITuner openTuner(int moduleId, in RadioManager.BandConfig bandConfig, boolean withAudio,
            in ITunerCallback callback, int targetSdkVersion);
            in ITunerCallback callback);

    ICloseHandle addAnnouncementListener(in int[] enabledTypes,
            in IAnnouncementListener listener);
+1 −3
Original line number Diff line number Diff line
@@ -1796,7 +1796,7 @@ public class RadioManager {
        ITuner tuner;
        TunerCallbackAdapter halCallback = new TunerCallbackAdapter(callback, handler);
        try {
            tuner = mService.openTuner(moduleId, config, withAudio, halCallback, mTargetSdkVersion);
            tuner = mService.openTuner(moduleId, config, withAudio, halCallback);
        } catch (RemoteException | IllegalArgumentException | IllegalStateException ex) {
            Log.e(TAG, "Failed to open tuner", ex);
            return null;
@@ -1873,7 +1873,6 @@ public class RadioManager {

    @NonNull private final Context mContext;
    @NonNull private final IRadioService mService;
    private final int mTargetSdkVersion;

    /**
     * @hide
@@ -1890,6 +1889,5 @@ public class RadioManager {
    public RadioManager(Context context, IRadioService service) {
        mContext = context;
        mService = service;
        mTargetSdkVersion = mContext.getApplicationInfo().targetSdkVersion;
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@
    package="com.android.frameworks.broadcastradiotests">

    <uses-permission android:name="android.permission.ACCESS_BROADCAST_RADIO" />
    <uses-permission android:name="android.permission.LOG_COMPAT_CHANGE" />
    <uses-permission android:name="android.permission.READ_COMPAT_CHANGE_CONFIG" />

    <application android:debuggable="true">
        <uses-library android:name="android.test.runner" />
+1 −1
Original line number Diff line number Diff line
@@ -580,7 +580,7 @@ public final class ProgramListTest {
        doAnswer(invocation -> {
            mTunerCallback = (ITunerCallback) invocation.getArguments()[3];
            return mTunerMock;
        }).when(mRadioServiceMock).openTuner(anyInt(), any(), anyBoolean(), any(), anyInt());
        }).when(mRadioServiceMock).openTuner(anyInt(), any(), anyBoolean(), any());

        mRadioTuner = radioManager.openTuner(/* moduleId= */ 0, band,
                /* withAudio= */ true, mTunerCallbackMock, /* handler= */ null);
+2 −7
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ import static org.mockito.Mockito.when;
import android.annotation.Nullable;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.os.Build;
import android.os.Parcel;
import android.os.RemoteException;
import android.util.ArrayMap;
@@ -50,8 +49,6 @@ import java.util.Set;
@RunWith(MockitoJUnitRunner.class)
public final class RadioManagerTest {

    private static final int TEST_TARGET_SDK_VERSION = Build.VERSION_CODES.CUR_DEVELOPMENT;

    private static final int REGION = RadioManager.REGION_ITU_2;
    private static final int FM_LOWER_LIMIT = 87500;
    private static final int FM_UPPER_LIMIT = 108000;
@@ -1043,14 +1040,13 @@ public final class RadioManagerTest {
        mRadioManager.openTuner(moduleId, FM_BAND_CONFIG, withAudio, mCallbackMock,
                /* handler= */ null);

        verify(mRadioServiceMock).openTuner(eq(moduleId), eq(FM_BAND_CONFIG), eq(withAudio), any(),
                anyInt());
        verify(mRadioServiceMock).openTuner(eq(moduleId), eq(FM_BAND_CONFIG), eq(withAudio), any());
    }

    @Test
    public void openTuner_whenServiceDied_returnsNull() throws Exception {
        createRadioManager();
        when(mRadioServiceMock.openTuner(anyInt(), any(), anyBoolean(), any(), anyInt()))
        when(mRadioServiceMock.openTuner(anyInt(), any(), anyBoolean(), any()))
                .thenThrow(new RemoteException());

        RadioTuner nullTuner = mRadioManager.openTuner(/* moduleId= */ 0, FM_BAND_CONFIG,
@@ -1166,7 +1162,6 @@ public final class RadioManagerTest {
    }

    private void createRadioManager() throws RemoteException {
        mApplicationInfo.targetSdkVersion = TEST_TARGET_SDK_VERSION;
        when(mContextMock.getApplicationInfo()).thenReturn(mApplicationInfo);
        when(mRadioServiceMock.listModules()).thenReturn(Arrays.asList(AMFM_PROPERTIES));
        when(mRadioServiceMock.addAnnouncementListener(any(), any())).thenReturn(mCloseHandleMock);
Loading