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

Commit 7fd495d4 authored by Ray Chin's avatar Ray Chin
Browse files

Add isLnaSupported API

Bug: 239240674
Test: atest android.media.tv.tuner.cts with cf_x86_tv-userdebug
Change-Id: Id6dda8b039f27c31c01c99c040943119d597be79
parent 353350bd
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -7175,6 +7175,7 @@ package android.media.tv.tuner {
    method @NonNull public java.util.List<android.media.tv.tuner.frontend.FrontendStatusReadiness> getFrontendStatusReadiness(@NonNull int[]);
    method @IntRange(from=0xffffffff) public int getMaxNumberOfFrontends(int);
    method @RequiresPermission("android.permission.TUNER_RESOURCE_ACCESS") public boolean hasUnusedFrontend(int);
    method public boolean isLnaSupported();
    method public boolean isLowestPriority(int);
    method @Nullable @RequiresPermission(android.Manifest.permission.ACCESS_TV_DESCRAMBLER) public android.media.tv.tuner.Descrambler openDescrambler();
    method @Nullable public android.media.tv.tuner.dvr.DvrPlayback openDvrPlayback(long, @NonNull java.util.concurrent.Executor, @NonNull android.media.tv.tuner.dvr.OnPlaybackStatusChangedListener);
+23 −1
Original line number Diff line number Diff line
@@ -998,6 +998,7 @@ public class Tuner implements AutoCloseable {
    private native int nativeScan(int settingsType, FrontendSettings settings, int scanType);
    private native int nativeStopScan();
    private native int nativeSetLnb(Lnb lnb);
    private native boolean nativeIsLnaSupported();
    private native int nativeSetLna(boolean enable);
    private native FrontendStatus nativeGetFrontendStatus(int[] statusTypes);
    private native Integer nativeGetAvSyncHwId(Filter filter);
@@ -1381,12 +1382,33 @@ public class Tuner implements AutoCloseable {
        }
    }

    /**
     * Is Low Noise Amplifier (LNA) supported by the Tuner.
     *
     * <p>This API is only supported by Tuner HAL 3.0 or higher.
     * Unsupported version would throw UnsupportedOperationException. Use
     * {@link TunerVersionChecker#getTunerVersion()} to check the version.
     *
     * @return {@code true} if supported, otherwise {@code false}.
     * @throws UnsupportedOperationException if the Tuner HAL version is lower than 3.0
     * @see android.media.tv.tuner.TunerVersionChecker#TUNER_VERSION_3_0
     */
    public boolean isLnaSupported() {
        if (!TunerVersionChecker.checkHigherOrEqualVersionTo(
                TunerVersionChecker.TUNER_VERSION_3_0, "isLnaSupported")) {
            throw new UnsupportedOperationException("Tuner HAL version "
                    + TunerVersionChecker.getTunerVersion() + " doesn't support this method.");
        }
        return nativeIsLnaSupported();
    }

    /**
     * Enable or Disable Low Noise Amplifier (LNA).
     *
     * @param enable {@code true} to activate LNA module; {@code false} to deactivate LNA.
     *
     * @return result status of the operation.
     * @return result status of the operation. {@link #RESULT_UNAVAILABLE} if the device doesn't
     *         support LNA.
     */
    @Result
    public int setLnaEnabled(boolean enable) {
+13 −0
Original line number Diff line number Diff line
@@ -1785,6 +1785,13 @@ int JTuner::setLnb(sp<LnbClient> lnbClient) {
    return (int)result;
}

bool JTuner::isLnaSupported() {
    if (sTunerClient == nullptr) {
        return (int)Result::NOT_INITIALIZED;
    }
    return sTunerClient->isLnaSupported();
}

int JTuner::setLna(bool enable) {
    if (sTunerClient == nullptr) {
        return (int)Result::NOT_INITIALIZED;
@@ -3482,6 +3489,11 @@ static int android_media_tv_Tuner_set_lnb(JNIEnv *env, jobject thiz, jobject lnb
    return tuner->setLnb(lnbClient);
}

static bool android_media_tv_Tuner_is_lna_supported(JNIEnv *env, jobject thiz) {
    sp<JTuner> tuner = getTuner(env, thiz);
    return tuner->isLnaSupported();
}

static int android_media_tv_Tuner_set_lna(JNIEnv *env, jobject thiz, jboolean enable) {
    sp<JTuner> tuner = getTuner(env, thiz);
    return tuner->setLna(enable);
@@ -4730,6 +4742,7 @@ static const JNINativeMethod gTunerMethods[] = {
            (void *)android_media_tv_Tuner_scan },
    { "nativeStopScan", "()I", (void *)android_media_tv_Tuner_stop_scan },
    { "nativeSetLnb", "(Landroid/media/tv/tuner/Lnb;)I", (void *)android_media_tv_Tuner_set_lnb },
    { "nativeIsLnaSupported", "()Z", (void *)android_media_tv_Tuner_is_lna_supported },
    { "nativeSetLna", "(Z)I", (void *)android_media_tv_Tuner_set_lna },
    { "nativeGetFrontendStatus", "([I)Landroid/media/tv/tuner/frontend/FrontendStatus;",
            (void *)android_media_tv_Tuner_get_frontend_status },
+1 −0
Original line number Diff line number Diff line
@@ -189,6 +189,7 @@ struct JTuner : public RefBase {
    int scan(const FrontendSettings& settings, FrontendScanType scanType);
    int stopScan();
    int setLnb(sp<LnbClient> lnbClient);
    bool isLnaSupported();
    int setLna(bool enable);
    jobject openLnbByHandle(int handle);
    jobject openLnbByName(jstring name);
+13 −0
Original line number Diff line number Diff line
@@ -210,4 +210,17 @@ int TunerClient::getMaxNumberOfFrontends(FrontendType frontendType) {
    return -1;
}

bool TunerClient::isLnaSupported() {
    if (mTunerService != nullptr) {
        bool lnaSupported;
        Status s = mTunerService->isLnaSupported(&lnaSupported);
        if (!s.isOk()) {
            return false;
        }
        return lnaSupported;
    }

    return false;
}

}  // namespace android
Loading