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

Commit 1ae34f90 authored by Tomasz Wasilczyk's avatar Tomasz Wasilczyk Committed by Android (Google) Code Review
Browse files

Merge "Implement step and scan calls of ITuner."

parents ea5e8016 2383793e
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -37,4 +37,25 @@ interface ITuner {
    void setMuted(boolean mute);

    boolean isMuted();

    /**
     * @throws IllegalStateException if called out of sequence
     */
    void step(boolean directionDown, boolean skipSubChannel);

    /**
     * @throws IllegalStateException if called out of sequence
     */
    void scan(boolean directionDown, boolean skipSubChannel);

    /**
     * @throws IllegalArgumentException if invalid arguments are passed
     * @throws IllegalStateException if called out of sequence
     */
    void tune(int channel, int subChannel);

    /**
     * @throws IllegalStateException if called out of sequence
     */
    void cancel();
}
+1 −0
Original line number Diff line number Diff line
@@ -22,4 +22,5 @@ import android.hardware.radio.RadioManager;
oneway interface ITunerCallback {
    void onError(int status);
    void onConfigurationChanged(in RadioManager.BandConfig config);
    void onProgramInfoChanged(in RadioManager.ProgramInfo info);
}
+20 −4
Original line number Diff line number Diff line
@@ -109,14 +109,30 @@ class TunerAdapter extends RadioTuner {

    @Override
    public int step(int direction, boolean skipSubChannel) {
        // TODO(b/36863239): forward to mTuner
        throw new RuntimeException("Not implemented");
        try {
            mTuner.step(direction == RadioTuner.DIRECTION_DOWN, skipSubChannel);
        } catch (IllegalStateException e) {
            Log.e(TAG, "Can't step", e);
            return RadioManager.STATUS_INVALID_OPERATION;
        } catch (RemoteException e) {
            Log.e(TAG, "service died", e);
            return RadioManager.STATUS_DEAD_OBJECT;
        }
        return RadioManager.STATUS_OK;
    }

    @Override
    public int scan(int direction, boolean skipSubChannel) {
        // TODO(b/36863239): forward to mTuner
        throw new RuntimeException("Not implemented");
        try {
            mTuner.scan(direction == RadioTuner.DIRECTION_DOWN, skipSubChannel);
        } catch (IllegalStateException e) {
            Log.e(TAG, "Can't scan", e);
            return RadioManager.STATUS_INVALID_OPERATION;
        } catch (RemoteException e) {
            Log.e(TAG, "service died", e);
            return RadioManager.STATUS_DEAD_OBJECT;
        }
        return RadioManager.STATUS_OK;
    }

    @Override
+5 −7
Original line number Diff line number Diff line
@@ -20,18 +20,11 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.Handler;
import android.os.Looper;
import android.os.RemoteException;
import android.util.Log;

import java.util.ArrayList;
import java.util.List;

/**
 * Implements the ITunerCallback interface by forwarding calls to RadioTuner.Callback.
 */
class TunerCallbackAdapter extends ITunerCallback.Stub {
    private static final String TAG = "radio.TunerCallbackAdapter";

    @NonNull private final RadioTuner.Callback mCallback;
    @NonNull private final Handler mHandler;

@@ -53,4 +46,9 @@ class TunerCallbackAdapter extends ITunerCallback.Stub {
    public void onConfigurationChanged(RadioManager.BandConfig config) {
        mHandler.post(() -> mCallback.onConfigurationChanged(config));
    }

    @Override
    public void onProgramInfoChanged(RadioManager.ProgramInfo info) {
        mHandler.post(() -> mCallback.onProgramInfoChanged(info));
    }
}
+36 −3
Original line number Diff line number Diff line
@@ -36,10 +36,10 @@ class Tuner extends ITuner.Stub {
    private int mRegion;  // TODO(b/36863239): find better solution to manage regions
    private final boolean mWithAudio;

    Tuner(@NonNull ITunerCallback clientCallback, int region, boolean withAudio) {
    Tuner(@NonNull ITunerCallback clientCallback, int halRev, int region, boolean withAudio) {
        mRegion = region;
        mWithAudio = withAudio;
        mNativeContext = nativeInit(clientCallback);
        mNativeContext = nativeInit(clientCallback, halRev);
    }

    @Override
@@ -48,7 +48,7 @@ class Tuner extends ITuner.Stub {
        super.finalize();
    }

    private native long nativeInit(@NonNull ITunerCallback clientCallback);
    private native long nativeInit(@NonNull ITunerCallback clientCallback, int halRev);
    private native void nativeFinalize(long nativeContext);
    private native void nativeClose(long nativeContext);

@@ -56,6 +56,11 @@ class Tuner extends ITuner.Stub {
            @NonNull RadioManager.BandConfig config);
    private native RadioManager.BandConfig nativeGetConfiguration(long nativeContext, int region);

    private native void nativeStep(long nativeContext, boolean directionDown, boolean skipSubChannel);
    private native void nativeScan(long nativeContext, boolean directionDown, boolean skipSubChannel);
    private native void nativeTune(long nativeContext, int channel, int subChannel);
    private native void nativeCancel(long nativeContext);

    @Override
    public void close() {
        synchronized (mLock) {
@@ -114,4 +119,32 @@ class Tuner extends ITuner.Stub {
            return mIsMuted;
        }
    }

    @Override
    public void step(boolean directionDown, boolean skipSubChannel) {
        synchronized (mLock) {
            nativeStep(mNativeContext, directionDown, skipSubChannel);
        }
    }

    @Override
    public void scan(boolean directionDown, boolean skipSubChannel) {
        synchronized (mLock) {
            nativeScan(mNativeContext, directionDown, skipSubChannel);
        }
    }

    @Override
    public void tune(int channel, int subChannel) {
        synchronized (mLock) {
            nativeTune(mNativeContext, channel, subChannel);
        }
    }

    @Override
    public void cancel() {
        synchronized (mLock) {
            nativeCancel(mNativeContext);
        }
    }
}
Loading