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

Commit 22dccd66 authored by Nick Chalko's avatar Nick Chalko
Browse files

Create ScanCallback

Test:   m framework-minus-apex
Change-Id: I3583a356364f4667473c315a52a23bc9e6e21712
parent 9672b8e2
Loading
Loading
Loading
Loading
+24 −26
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.media.tv.tuner;

import android.annotation.CallbackExecutor;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
@@ -30,11 +31,13 @@ import android.media.tv.tuner.filter.FilterEvent;
import android.media.tv.tuner.frontend.FrontendCallback;
import android.media.tv.tuner.frontend.FrontendInfo;
import android.media.tv.tuner.frontend.FrontendStatus;
import android.media.tv.tuner.frontend.ScanCallback;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;

import java.util.List;
import java.util.concurrent.Executor;

/**
 * This class is used to interact with hardware tuners devices.
@@ -68,6 +71,10 @@ public final class Tuner implements AutoCloseable {

    private List<Integer> mLnbIds;
    private Lnb mLnb;
    @Nullable
    private ScanCallback mScanCallback;
    @Nullable
    private Executor mScanCallbackExecutor;

    /**
     * Constructs a Tuner instance.
@@ -229,29 +236,6 @@ public final class Tuner implements AutoCloseable {
        private Frontend(int id) {
            mId = id;
        }

        public void setCallback(@Nullable FrontendCallback callback, @Nullable Handler handler) {
            mCallback = callback;

            if (mCallback == null) {
                return;
            }

            if (handler == null) {
                // use default looper if handler is null
                if (mHandler == null) {
                    mHandler = createEventHandler();
                }
                return;
            }

            Looper looper = handler.getLooper();
            if (mHandler != null && mHandler.getLooper() == looper) {
                // the same looper. reuse mHandler
                return;
            }
            mHandler = new EventHandler(looper);
        }
    }

    /**
@@ -284,18 +268,32 @@ public final class Tuner implements AutoCloseable {
     * Scan channels.
     * @hide
     */
    public int scan(@NonNull FrontendSettings settings, @FrontendScanType int scanType) {
    @RequiresPermission(android.Manifest.permission.ACCESS_TV_TUNER)
    public int scan(@NonNull FrontendSettings settings, @FrontendScanType int scanType,
            @NonNull @CallbackExecutor Executor executor, @NonNull ScanCallback scanCallback) {
        mScanCallback = scanCallback;
        mScanCallbackExecutor = executor;
        return nativeScan(settings.getType(), settings, scanType);
    }

    /**
     * Stops a previous scanning.
     *
     * If the method completes successfully, the frontend stop previous scanning.
     * <p>
     * The {@link ScanCallback} and it's {@link Executor} will be removed.
     *
     * <p>
     * If the method completes successfully, the frontend stopped previous scanning.
     *
     * @hide
     */
    @RequiresPermission(android.Manifest.permission.ACCESS_TV_TUNER)
    public int stopScan() {
        return nativeStopScan();
        TunerUtils.checkTunerPermission(mContext);
        int retVal = nativeStopScan();
        mScanCallback = null;
        mScanCallbackExecutor = null;
        return retVal;
    }

    /**
+20 −3
Original line number Diff line number Diff line
@@ -978,10 +978,13 @@ public final class TunerConstants {
            Constants.FrontendAtsc3DemodOutputFormat.BASEBAND_PACKET;

    /** @hide */
    @IntDef({FRONTEND_DVBS_STANDARD_AUTO, FRONTEND_DVBS_STANDARD_S, FRONTEND_DVBS_STANDARD_S2,
    @IntDef(prefix = "FRONTEND_DVBS_STANDARD",
            value = {FRONTEND_DVBS_STANDARD_AUTO, FRONTEND_DVBS_STANDARD_S,
                    FRONTEND_DVBS_STANDARD_S2,
                    FRONTEND_DVBS_STANDARD_S2X})
    @Retention(RetentionPolicy.SOURCE)
    public @interface FrontendDvbsStandard {}
    public @interface FrontendDvbsStandard {
    }
    /** @hide */
    public static final int FRONTEND_DVBS_STANDARD_AUTO = Constants.FrontendDvbsStandard.AUTO;
    /** @hide */
@@ -1172,6 +1175,20 @@ public final class TunerConstants {
    public static final int FRONTEND_DVBT_GUARD_INTERVAL_INTERVAL_19_256 =
            Constants.FrontendDvbtGuardInterval.INTERVAL_19_256;

    /** @hide */
    @IntDef(prefix = "FRONTEND_DVBT_STANDARD",
            value = {FRONTEND_DVBT_STANDARD_AUTO, FRONTEND_DVBT_STANDARD_T,
                    FRONTEND_DVBT_STANDARD_T2}
    )
    @Retention(RetentionPolicy.SOURCE)
    public @interface FrontendDvbtStandard {}
    /** @hide */
    public static final int FRONTEND_DVBT_STANDARD_AUTO = Constants.FrontendDvbtStandard.AUTO;
    /** @hide */
    public static final int FRONTEND_DVBT_STANDARD_T = Constants.FrontendDvbtStandard.T;
    /** @hide */
    public static final int FRONTEND_DVBT_STANDARD_T2 = Constants.FrontendDvbtStandard.T2;

    /** @hide */
    @IntDef({FRONTEND_ISDBS_CODERATE_UNDEFINED, FRONTEND_ISDBS_CODERATE_AUTO,
            FRONTEND_ISDBS_CODERATE_1_2, FRONTEND_ISDBS_CODERATE_2_3, FRONTEND_ISDBS_CODERATE_3_4,
+0 −6
Original line number Diff line number Diff line
@@ -27,10 +27,4 @@ public interface FrontendCallback {
     * Invoked when there is a frontend event.
     */
    void onEvent(int frontendEventType);

    /**
     * Invoked when there is a scan message.
     * @param msg
     */
    void onScanMessage(ScanMessage msg);
}
+80 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.media.tv.tuner.frontend;

import android.media.tv.tuner.TunerConstants;

/**
 * Scan callback.
 *
 * @hide
 */
public interface ScanCallback {
    /** Scan locked the signal. */
    void onLocked(boolean isLocked);

    /** Scan stopped. */
    void onEnd(boolean isEnd);

    /** scan progress percent (0..100) */
    void onProgress(int percent);

    /** Signal frequency in Hertz */
    void onFrequencyReport(int frequency);

    /** Symbols per second */
    void onSymbolRate(int rate);

    /** Locked Plp Ids for DVBT2 frontend. */
    void onPlpIds(int[] plpIds);

    /** Locked group Ids for DVBT2 frontend. */
    void onGroupIds(int[] groupIds);

    /** Stream Ids. */
    void onInputStreamIds(int[] inputStreamIds);

    /** Locked signal standard. */
    void onDvbsStandard(@TunerConstants.FrontendDvbsStandard int dvbsStandandard);

    /** Locked signal standard. */
    void onDvbtStandard(@TunerConstants.FrontendDvbtStandard int dvbtStandard);

    /** PLP status in a tuned frequency band for ATSC3 frontend. */
    void onAtsc3PlpInfos(Atsc3PlpInfo[] atsc3PlpInfos);

    /** PLP information for ATSC3. */
    class Atsc3PlpInfo {
        private final int mPlpId;
        private final boolean mLlsFlag;

        private Atsc3PlpInfo(int plpId, boolean llsFlag) {
            mPlpId = plpId;
            mLlsFlag = llsFlag;
        }

        /** Gets PLP IDs. */
        public int getPlpId() {
            return mPlpId;
        }

        /** Gets LLS flag. */
        public boolean getLlsFlag() {
            return mLlsFlag;
        }
    }
}
+0 −172
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.media.tv.tuner.frontend;

import android.annotation.IntDef;
import android.hardware.tv.tuner.V1_0.Constants;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * Message from frontend during scan operations.
 *
 * @hide
 */
public class ScanMessage {

    /** @hide */
    @IntDef({
        LOCKED,
        END,
        PROGRESS_PERCENT,
        FREQUENCY,
        SYMBOL_RATE,
        PLP_IDS,
        GROUP_IDS,
        INPUT_STREAM_IDS,
        STANDARD,
        ATSC3_PLP_INFO
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface Type {}
    /** @hide */
    public static final int LOCKED = Constants.FrontendScanMessageType.LOCKED;
    /** @hide */
    public static final int END = Constants.FrontendScanMessageType.END;
    /** @hide */
    public static final int PROGRESS_PERCENT = Constants.FrontendScanMessageType.PROGRESS_PERCENT;
    /** @hide */
    public static final int FREQUENCY = Constants.FrontendScanMessageType.FREQUENCY;
    /** @hide */
    public static final int SYMBOL_RATE = Constants.FrontendScanMessageType.SYMBOL_RATE;
    /** @hide */
    public static final int PLP_IDS = Constants.FrontendScanMessageType.PLP_IDS;
    /** @hide */
    public static final int GROUP_IDS = Constants.FrontendScanMessageType.GROUP_IDS;
    /** @hide */
    public static final int INPUT_STREAM_IDS = Constants.FrontendScanMessageType.INPUT_STREAM_IDS;
    /** @hide */
    public static final int STANDARD = Constants.FrontendScanMessageType.STANDARD;
    /** @hide */
    public static final int ATSC3_PLP_INFO = Constants.FrontendScanMessageType.ATSC3_PLP_INFO;

    private final int mType;
    private final Object mValue;

    private ScanMessage(int type, Object value) {
        mType = type;
        mValue = value;
    }

    /** Gets scan message type. */
    @Type
    public int getMessageType() {
        return mType;
    }
    /** Message indicates whether frontend is locked or not. */
    public boolean getIsLocked() {
        if (mType != LOCKED) {
            throw new IllegalStateException();
        }
        return (Boolean) mValue;
    }
    /** Message indicates whether the scan has reached the end or not. */
    public boolean getIsEnd() {
        if (mType != END) {
            throw new IllegalStateException();
        }
        return (Boolean) mValue;
    }
    /** Progress message in percent. */
    public int getProgressPercent() {
        if (mType != PROGRESS_PERCENT) {
            throw new IllegalStateException();
        }
        return (Integer) mValue;
    }
    /** Gets frequency. */
    public int getFrequency() {
        if (mType != FREQUENCY) {
            throw new IllegalStateException();
        }
        return (Integer) mValue;
    }
    /** Gets symbol rate. */
    public int getSymbolRate() {
        if (mType != SYMBOL_RATE) {
            throw new IllegalStateException();
        }
        return (Integer) mValue;
    }
    /** Gets PLP IDs. */
    public int[] getPlpIds() {
        if (mType != PLP_IDS) {
            throw new IllegalStateException();
        }
        return (int[]) mValue;
    }
    /** Gets group IDs. */
    public int[] getGroupIds() {
        if (mType != GROUP_IDS) {
            throw new IllegalStateException();
        }
        return (int[]) mValue;
    }
    /** Gets Input stream IDs. */
    public int[] getInputStreamIds() {
        if (mType != INPUT_STREAM_IDS) {
            throw new IllegalStateException();
        }
        return (int[]) mValue;
    }
    /** Gets the DVB-T or DVB-S standard. */
    public int getStandard() {
        if (mType != STANDARD) {
            throw new IllegalStateException();
        }
        return (int) mValue;
    }

    /** Gets PLP information for ATSC3. */
    public Atsc3PlpInfo[] getAtsc3PlpInfos() {
        if (mType != ATSC3_PLP_INFO) {
            throw new IllegalStateException();
        }
        return (Atsc3PlpInfo[]) mValue;
    }

    /** PLP information for ATSC3. */
    public static class Atsc3PlpInfo {
        private final int mPlpId;
        private final boolean mLlsFlag;

        private Atsc3PlpInfo(int plpId, boolean llsFlag) {
            mPlpId = plpId;
            mLlsFlag = llsFlag;
        }

        /** Gets PLP IDs. */
        public int getPlpId() {
            return mPlpId;
        }
        /** Gets LLS flag. */
        public boolean getLlsFlag() {
            return mLlsFlag;
        }
    }
}