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

Commit d7c21d3c authored by Tomasz Wasilczyk's avatar Tomasz Wasilczyk
Browse files

Make RadioService actually talking to the HAL.

For now, only opening and closing a tuner is implemented.

Test: instrumentation, KitchenSink
Bug: b/36863239
Change-Id: Ib2e14c0108c0714524d50b9557f24465c68f5ef2
parent 39e00e12
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -24,5 +24,5 @@ import android.hardware.radio.ITuner;
 * {@hide}
 */
interface IRadioService {
    ITuner openTuner();
    ITuner openTuner(boolean withAudio);
}
+2 −0
Original line number Diff line number Diff line
@@ -20,5 +20,7 @@ import android.hardware.radio.RadioManager;

/** {@hide} */
interface ITuner {
    void close();

    int getProgramInformation(out RadioManager.ProgramInfo[] infoOut);
}
+5 −1
Original line number Diff line number Diff line
@@ -1448,10 +1448,14 @@ public class RadioManager {
        if (mService != null) {
            ITuner tuner;
            try {
                tuner = mService.openTuner();
                tuner = mService.openTuner(withAudio);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
            if (tuner == null) {
                Log.e(TAG, "Failed to open tuner");
                return null;
            }
            return new TunerAdapter(tuner);
        }

+13 −2
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ class TunerAdapter extends RadioTuner {
    private static final String TAG = "radio.TunerAdapter";

    @NonNull private final ITuner mTuner;
    private boolean mIsClosed = false;

    TunerAdapter(ITuner tuner) {
        if (tuner == null) {
@@ -41,8 +42,18 @@ class TunerAdapter extends RadioTuner {

    @Override
    public void close() {
        // TODO(b/36863239): forward to mTuner
        Log.w(TAG, "Close call not implemented");
        synchronized (mTuner) {
            if (mIsClosed) {
                Log.d(TAG, "Tuner is already closed");
                return;
            }
            mIsClosed = true;
        }
        try {
            mTuner.close();
        } catch (RemoteException e) {
            Log.e(TAG, "Exception trying to close tuner", e);
        }
    }

    @Override
+21 −13
Original line number Diff line number Diff line
@@ -28,29 +28,37 @@ public class RadioService extends SystemService {
    // TODO(b/36863239): rename to RadioService when native service goes away
    private static final String TAG = "RadioServiceJava";

    private final RadioServiceImpl mServiceImpl = new RadioServiceImpl();

    /**
     * This field is used by native code, do not access or modify.
     */
    private final long mNativeContext = nativeInit();

    public RadioService(Context context) {
        super(context);
    }

    @Override
    public void onStart() {
        publishBinderService(Context.RADIO_SERVICE, new RadioServiceImpl());
        Slog.v(TAG, "RadioService started");
    protected void finalize() throws Throwable {
        nativeFinalize(mNativeContext);
        super.finalize();
    }

    private static class RadioServiceImpl extends IRadioService.Stub {
    private native long nativeInit();
    private native void nativeFinalize(long nativeContext);
    private native Tuner openTunerNative(long nativeContext, boolean withAudio);

    @Override
        public ITuner openTuner() {
            Slog.d(TAG, "openTuner()");
            return new TunerImpl();
        }
    public void onStart() {
        publishBinderService(Context.RADIO_SERVICE, mServiceImpl);
        Slog.v(TAG, "RadioService started");
    }

    private static class TunerImpl extends ITuner.Stub {
    private class RadioServiceImpl extends IRadioService.Stub {
        @Override
        public int getProgramInformation(RadioManager.ProgramInfo[] infoOut) {
            Slog.d(TAG, "getProgramInformation()");
            return RadioManager.STATUS_INVALID_OPERATION;
        public ITuner openTuner(boolean withAudio) {
            return openTunerNative(mNativeContext, withAudio);
        }
    }
}
Loading