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

Commit ced9e705 authored by Weilin Xu's avatar Weilin Xu Committed by Android (Google) Code Review
Browse files

Merge "Add log info for BroadcastRadioService" into tm-qpr-dev

parents 7738b570 01dc7ddc
Loading
Loading
Loading
Loading
+4 −6
Original line number Diff line number Diff line
@@ -39,7 +39,6 @@ import java.util.OptionalInt;

public class BroadcastRadioService extends SystemService {
    private static final String TAG = "BcRadioSrv";
    private static final boolean DEBUG = false;

    private final ServiceImpl mServiceImpl = new ServiceImpl();

@@ -74,6 +73,7 @@ public class BroadcastRadioService extends SystemService {

        @Override
        public List<RadioManager.ModuleProperties> listModules() {
            Slog.v(TAG, "Listing HIDL modules");
            enforcePolicyAccess();
            List<RadioManager.ModuleProperties> modules = new ArrayList<>();
            modules.addAll(mV1Modules);
@@ -84,7 +84,7 @@ public class BroadcastRadioService extends SystemService {
        @Override
        public ITuner openTuner(int moduleId, RadioManager.BandConfig bandConfig,
                boolean withAudio, ITunerCallback callback) throws RemoteException {
            if (DEBUG) Slog.i(TAG, "Opening module " + moduleId);
            Slog.v(TAG, "Opening module " + moduleId);
            enforcePolicyAccess();
            if (callback == null) {
                throw new IllegalArgumentException("Callback must not be empty");
@@ -101,16 +101,14 @@ public class BroadcastRadioService extends SystemService {
        @Override
        public ICloseHandle addAnnouncementListener(int[] enabledTypes,
                IAnnouncementListener listener) {
            if (DEBUG) {
                Slog.i(TAG, "Adding announcement listener for " + Arrays.toString(enabledTypes));
            }
            Slog.v(TAG, "Adding announcement listener for " + Arrays.toString(enabledTypes));
            Objects.requireNonNull(enabledTypes);
            Objects.requireNonNull(listener);
            enforcePolicyAccess();

            synchronized (mLock) {
                if (!mHal2.hasAnyModules()) {
                    Slog.i(TAG, "There are no HAL 2.x modules registered");
                    Slog.i(TAG, "There are no HAL 2.0 modules registered");
                    return new AnnouncementAggregator(listener, mLock);
                }

+4 −1
Original line number Diff line number Diff line
@@ -132,6 +132,7 @@ public class BroadcastRadioService {
    }

    public @NonNull Collection<RadioManager.ModuleProperties> listModules() {
        Slog.v(TAG, "List HIDL 2.0 modules");
        synchronized (mLock) {
            return mModules.values().stream().map(module -> module.mProperties)
                    .collect(Collectors.toList());
@@ -152,10 +153,11 @@ public class BroadcastRadioService {

    public ITuner openSession(int moduleId, @Nullable RadioManager.BandConfig legacyConfig,
        boolean withAudio, @NonNull ITunerCallback callback) throws RemoteException {
        Slog.v(TAG, "Open HIDL 2.0 session");
        Objects.requireNonNull(callback);

        if (!withAudio) {
            throw new IllegalArgumentException("Non-audio sessions not supported with HAL 2.x");
            throw new IllegalArgumentException("Non-audio sessions not supported with HAL 2.0");
        }

        RadioModule module = null;
@@ -175,6 +177,7 @@ public class BroadcastRadioService {

    public ICloseHandle addAnnouncementListener(@NonNull int[] enabledTypes,
            @NonNull IAnnouncementListener listener) {
        Slog.v(TAG, "Add announcementListener");
        AnnouncementAggregator aggregator = new AnnouncementAggregator(listener, mLock);
        boolean anySupported = false;
        synchronized (mLock) {
+11 −3
Original line number Diff line number Diff line
@@ -142,8 +142,12 @@ class RadioModule {
    public static @Nullable RadioModule tryLoadingModule(int idx, @NonNull String fqName,
            Object lock) {
        try {
            Slog.i(TAG, "Try loading module for idx " + idx + ", fqName " + fqName);
            IBroadcastRadio service = IBroadcastRadio.getService(fqName);
            if (service == null) return null;
            if (service == null) {
                Slog.w(TAG, "No service found for fqName " + fqName);
                return null;
            }

            Mutable<AmFmRegionConfig> amfmConfig = new Mutable<>();
            service.getAmFmRegionConfig(false, (result, config) -> {
@@ -160,7 +164,7 @@ class RadioModule {

            return new RadioModule(service, prop, lock);
        } catch (RemoteException ex) {
            Slog.e(TAG, "failed to load module " + fqName, ex);
            Slog.e(TAG, "Failed to load module " + fqName, ex);
            return null;
        }
    }
@@ -171,6 +175,7 @@ class RadioModule {

    public @NonNull TunerSession openSession(@NonNull android.hardware.radio.ITunerCallback userCb)
            throws RemoteException {
        Slog.i(TAG, "Open TunerSession");
        synchronized (mLock) {
            if (mHalTunerSession == null) {
                Mutable<ITunerSession> hwSession = new Mutable<>();
@@ -201,6 +206,7 @@ class RadioModule {
        // Copy the contents of mAidlTunerSessions into a local array because TunerSession.close()
        // must be called without mAidlTunerSessions locked because it can call
        // onTunerSessionClosed().
        Slog.i(TAG, "Close TunerSessions");
        TunerSession[] tunerSessions;
        synchronized (mLock) {
            tunerSessions = new TunerSession[mAidlTunerSessions.size()];
@@ -313,7 +319,7 @@ class RadioModule {
        }
        onTunerSessionProgramListFilterChanged(null);
        if (mAidlTunerSessions.isEmpty() && mHalTunerSession != null) {
            Slog.v(TAG, "closing HAL tuner session");
            Slog.i(TAG, "Closing HAL tuner session");
            try {
                mHalTunerSession.close();
            } catch (RemoteException ex) {
@@ -365,6 +371,7 @@ class RadioModule {

    public android.hardware.radio.ICloseHandle addAnnouncementListener(@NonNull int[] enabledTypes,
            @NonNull android.hardware.radio.IAnnouncementListener listener) throws RemoteException {
        Slog.i(TAG, "Add AnnouncementListener");
        ArrayList<Byte> enabledList = new ArrayList<>();
        for (int type : enabledTypes) {
            enabledList.add((byte)type);
@@ -401,6 +408,7 @@ class RadioModule {
    }

    Bitmap getImage(int id) {
        Slog.i(TAG, "Get image for id " + id);
        if (id == 0) throw new IllegalArgumentException("Image ID is missing");

        byte[] rawImage;
+27 −5
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.hardware.radio.ProgramList;
import android.hardware.radio.ProgramSelector;
import android.hardware.radio.RadioManager;
import android.os.RemoteException;
import android.util.Log;
import android.util.MutableBoolean;
import android.util.MutableInt;
import android.util.Slog;
@@ -61,8 +62,13 @@ class TunerSession extends ITuner.Stub {
        mLock = Objects.requireNonNull(lock);
    }

    private boolean isDebugEnabled() {
        return Log.isLoggable(TAG, Log.DEBUG);
    }

    @Override
    public void close() {
        if (isDebugEnabled()) Slog.d(TAG, "Close");
        close(null);
    }

@@ -74,6 +80,7 @@ class TunerSession extends ITuner.Stub {
     * @param error Optional error to send to client before session is closed.
     */
    public void close(@Nullable Integer error) {
        if (isDebugEnabled()) Slog.d(TAG, "Close on error " + error);
        synchronized (mLock) {
            if (mIsClosed) return;
            if (error != null) {
@@ -104,7 +111,7 @@ class TunerSession extends ITuner.Stub {
        synchronized (mLock) {
            checkNotClosedLocked();
            mDummyConfig = Objects.requireNonNull(config);
            Slog.i(TAG, "Ignoring setConfiguration - not applicable for broadcastradio HAL 2.x");
            Slog.i(TAG, "Ignoring setConfiguration - not applicable for broadcastradio HAL 2.0");
            mModule.fanoutAidlCallback(cb -> cb.onConfigurationChanged(config));
        }
    }
@@ -137,6 +144,10 @@ class TunerSession extends ITuner.Stub {

    @Override
    public void step(boolean directionDown, boolean skipSubChannel) throws RemoteException {
        if (isDebugEnabled()) {
            Slog.d(TAG, "Step with directionDown " + directionDown
                    + " skipSubChannel " + skipSubChannel);
        }
        synchronized (mLock) {
            checkNotClosedLocked();
            int halResult = mHwSession.step(!directionDown);
@@ -146,6 +157,10 @@ class TunerSession extends ITuner.Stub {

    @Override
    public void scan(boolean directionDown, boolean skipSubChannel) throws RemoteException {
        if (isDebugEnabled()) {
            Slog.d(TAG, "Scan with directionDown " + directionDown
                    + " skipSubChannel " + skipSubChannel);
        }
        synchronized (mLock) {
            checkNotClosedLocked();
            int halResult = mHwSession.scan(!directionDown, skipSubChannel);
@@ -155,6 +170,7 @@ class TunerSession extends ITuner.Stub {

    @Override
    public void tune(ProgramSelector selector) throws RemoteException {
        if (isDebugEnabled()) Slog.d(TAG, "Tune with selector " + selector);
        synchronized (mLock) {
            checkNotClosedLocked();
            int halResult = mHwSession.tune(Convert.programSelectorToHal(selector));
@@ -164,6 +180,7 @@ class TunerSession extends ITuner.Stub {

    @Override
    public void cancel() {
        Slog.i(TAG, "Cancel");
        synchronized (mLock) {
            checkNotClosedLocked();
            Utils.maybeRethrow(mHwSession::cancel);
@@ -172,23 +189,25 @@ class TunerSession extends ITuner.Stub {

    @Override
    public void cancelAnnouncement() {
        Slog.i(TAG, "Announcements control doesn't involve cancelling at the HAL level in 2.x");
        Slog.i(TAG, "Announcements control doesn't involve cancelling at the HAL level in HAL 2.0");
    }

    @Override
    public Bitmap getImage(int id) {
        if (isDebugEnabled()) Slog.d(TAG, "Get image for " + id);
        return mModule.getImage(id);
    }

    @Override
    public boolean startBackgroundScan() {
        Slog.i(TAG, "Explicit background scan trigger is not supported with HAL 2.x");
        Slog.i(TAG, "Explicit background scan trigger is not supported with HAL 2.0");
        mModule.fanoutAidlCallback(cb -> cb.onBackgroundScanComplete());
        return true;
    }

    @Override
    public void startProgramListUpdates(ProgramList.Filter filter) throws RemoteException {
        if (isDebugEnabled()) Slog.d(TAG, "start programList updates " + filter);
        // If the AIDL client provides a null filter, it wants all updates, so use the most broad
        // filter.
        if (filter == null) {
@@ -247,6 +266,7 @@ class TunerSession extends ITuner.Stub {

    @Override
    public void stopProgramListUpdates() throws RemoteException {
        if (isDebugEnabled()) Slog.d(TAG, "Stop programList updates");
        synchronized (mLock) {
            checkNotClosedLocked();
            mProgramInfoCache = null;
@@ -270,7 +290,7 @@ class TunerSession extends ITuner.Stub {

    @Override
    public boolean isConfigFlagSet(int flag) {
        Slog.v(TAG, "isConfigFlagSet " + ConfigFlag.toString(flag));
        if (isDebugEnabled()) Slog.d(TAG, "Is ConfigFlagSet for " + ConfigFlag.toString(flag));
        synchronized (mLock) {
            checkNotClosedLocked();

@@ -292,7 +312,9 @@ class TunerSession extends ITuner.Stub {

    @Override
    public void setConfigFlag(int flag, boolean value) throws RemoteException {
        Slog.v(TAG, "setConfigFlag " + ConfigFlag.toString(flag) + " = " + value);
        if (isDebugEnabled()) {
            Slog.d(TAG, "Set ConfigFlag " + ConfigFlag.toString(flag) + " = " + value);
        }
        synchronized (mLock) {
            checkNotClosedLocked();
            int halResult = mHwSession.setConfigFlag(flag, value);