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

Commit d5b09e89 authored by Hongguang Chen's avatar Hongguang Chen Committed by Android (Google) Code Review
Browse files

Merge "Support frontend status readiness query."

parents 1ef34605 9efb9dca
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -6795,6 +6795,7 @@ package android.media.tv.tuner {
    method @Nullable public android.media.tv.tuner.DemuxCapabilities getDemuxCapabilities();
    method @Nullable public android.media.tv.tuner.frontend.FrontendInfo getFrontendInfo();
    method @Nullable public android.media.tv.tuner.frontend.FrontendStatus getFrontendStatus(@NonNull int[]);
    method @Nullable public 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 isLowestPriority(int);
@@ -8039,6 +8040,16 @@ package android.media.tv.tuner.frontend {
    method public boolean isLocked();
  }
  public class FrontendStatusReadiness {
    method public int getStatusReadiness();
    method public int getStatusType();
    field public static final int FRONTEND_STATUS_READINESS_STABLE = 3; // 0x3
    field public static final int FRONTEND_STATUS_READINESS_UNAVAILABLE = 1; // 0x1
    field public static final int FRONTEND_STATUS_READINESS_UNDEFINED = 0; // 0x0
    field public static final int FRONTEND_STATUS_READINESS_UNSTABLE = 2; // 0x2
    field public static final int FRONTEND_STATUS_READINESS_UNSUPPORTED = 4; // 0x4
  }
  public class Isdbs3FrontendCapabilities extends android.media.tv.tuner.frontend.FrontendCapabilities {
    method public int getCodeRateCapability();
    method public int getModulationCapability();
+34 −2
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import android.media.tv.tuner.frontend.FrontendInfo;
import android.media.tv.tuner.frontend.FrontendSettings;
import android.media.tv.tuner.frontend.FrontendStatus;
import android.media.tv.tuner.frontend.FrontendStatus.FrontendStatusType;
import android.media.tv.tuner.frontend.FrontendStatusReadiness;
import android.media.tv.tuner.frontend.OnTuneEventListener;
import android.media.tv.tuner.frontend.ScanCallback;
import android.media.tv.tunerresourcemanager.ResourceClientProfile;
@@ -61,9 +62,7 @@ import android.os.Looper;
import android.os.Message;
import android.os.Process;
import android.util.Log;

import com.android.internal.util.FrameworkStatsLog;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.ref.WeakReference;
@@ -1005,6 +1004,7 @@ public class Tuner implements AutoCloseable {
    private native int nativeRemoveOutputPid(int pid);
    private native Lnb nativeOpenLnbByHandle(int handle);
    private native Lnb nativeOpenLnbByName(String name);
    private native FrontendStatusReadiness[] nativeGetFrontendStatusReadiness(int[] statusTypes);

    private native Descrambler nativeOpenDescramblerByHandle(int handle);
    private native int nativeOpenDemuxByhandle(int handle);
@@ -1594,6 +1594,38 @@ public class Tuner implements AutoCloseable {
        }
    }

    /**
     * Gets Frontend Status Readiness statuses for given status types.
     *
     * <p>This API is only supported by Tuner HAL 2.0 or higher. Unsupported versions would cause
     * no-op. Use {@link TunerVersionChecker#getTunerVersion()} to check the version.
     *
     * @param statusTypes an array of status types.
     *
     * @return an array of current readiness states. {@code null} if the operation failed or
     *         unsupported versions.
     * @throws IllegalStateException if there is no active frontend currently.
     */
    @Nullable
    @SuppressLint("ArrayReturn")
    @SuppressWarnings("NullableCollection")
    public FrontendStatusReadiness[] getFrontendStatusReadiness(
            @NonNull @FrontendStatusType int[] statusTypes) {
        mFrontendLock.lock();
        try {
            if (!TunerVersionChecker.checkHigherOrEqualVersionTo(
                        TunerVersionChecker.TUNER_VERSION_2_0, "Remove output PID")) {
                return null;
            }
            if (mFrontend == null) {
                throw new IllegalStateException("frontend is not initialized");
            }
            return nativeGetFrontendStatusReadiness(statusTypes);
        } finally {
            mFrontendLock.unlock();
        }
    }

    /**
     * Gets the currently initialized and activated frontend information. To get all the available
     * frontend info on the device, use {@link getAvailableFrontendInfos()}.
+93 −0
Original line number Diff line number Diff line
/*
 * Copyright 2022 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.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.media.tv.tuner.frontend.FrontendStatus.FrontendStatusType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * A class contains the Frontend Status Readiness of a given type.
 *
 * @hide
 */
@SystemApi
public class FrontendStatusReadiness {
    /** @hide */
    @IntDef({FRONTEND_STATUS_READINESS_UNDEFINED, FRONTEND_STATUS_READINESS_UNAVAILABLE,
            FRONTEND_STATUS_READINESS_UNSTABLE, FRONTEND_STATUS_READINESS_STABLE,
            FRONTEND_STATUS_READINESS_UNSUPPORTED})
    @Retention(RetentionPolicy.SOURCE)
    public @interface Readiness {}

    /**
     * The FrontendStatus readiness status for the given FrontendStatusType is undefined.
     */
    public static final int FRONTEND_STATUS_READINESS_UNDEFINED =
            android.hardware.tv.tuner.FrontendStatusReadiness.UNDEFINED;

    /**
     * The FrontendStatus for the given FrontendStatusType is currently unavailable.
     */
    public static final int FRONTEND_STATUS_READINESS_UNAVAILABLE =
            android.hardware.tv.tuner.FrontendStatusReadiness.UNAVAILABLE;

    /**
     * The FrontendStatus for the given FrontendStatusType is ready to read, but it’s unstable.
     */
    public static final int FRONTEND_STATUS_READINESS_UNSTABLE =
            android.hardware.tv.tuner.FrontendStatusReadiness.UNSTABLE;

    /**
     * The FrontendStatus for the given FrontendStatusType is ready to read, and it’s stable.
     */
    public static final int FRONTEND_STATUS_READINESS_STABLE =
            android.hardware.tv.tuner.FrontendStatusReadiness.STABLE;

    /**
     * The FrontendStatus for the given FrontendStatusType is not supported.
     */
    public static final int FRONTEND_STATUS_READINESS_UNSUPPORTED =
            android.hardware.tv.tuner.FrontendStatusReadiness.UNSUPPORTED;

    @FrontendStatusType private int mFrontendStatusType;
    @Readiness private int mStatusReadiness;

    private FrontendStatusReadiness(int type, int readiness) {
        mFrontendStatusType = type;
        mStatusReadiness = readiness;
    }

    /**
     * Gets the frontend status type.
     */
    @FrontendStatusType
    public int getStatusType() {
        return mFrontendStatusType;
    }
    /**
     * Gets the frontend status readiness.
     */
    @Readiness
    public int getStatusReadiness() {
        return mStatusReadiness;
    }
}
+39 −0
Original line number Diff line number Diff line
@@ -1631,6 +1631,36 @@ jint JTuner::removeOutputPid(int32_t pid) {
    return (jint)mFeClient->removeOutputPid(pid);
}

jobjectArray JTuner::getFrontendStatusReadiness(jintArray types) {
    if (mFeClient == nullptr) {
        ALOGE("frontend is not initialized");
        return nullptr;
    }

    JNIEnv *env = AndroidRuntime::getJNIEnv();
    jsize size = env->GetArrayLength(types);
    jint intTypes[size];
    env->GetIntArrayRegion(types, 0, size, intTypes);
    std::vector<FrontendStatusType> v;
    for (int i = 0; i < size; i++) {
        v.push_back(static_cast<FrontendStatusType>(intTypes[i]));
    }

    vector<FrontendStatusReadiness> readiness = mFeClient->getStatusReadiness(v);
    if (readiness.size() < size) {
        return nullptr;
    }

    jclass clazz = env->FindClass("android/media/tv/tuner/frontend/FrontendStatusReadiness");
    jmethodID init = env->GetMethodID(clazz, "<init>", "(II)V");
    jobjectArray valObj = env->NewObjectArray(size, clazz, nullptr);
    for (int i = 0; i < size; i++) {
        jobject readinessObj = env->NewObject(clazz, init, intTypes[i], readiness[i]);
        env->SetObjectArrayElement(valObj, i, readinessObj);
    }
    return valObj;
}

jobject JTuner::openLnbByHandle(int handle) {
    if (mTunerClient == nullptr) {
        return nullptr;
@@ -4389,6 +4419,12 @@ static jint android_media_tv_Tuner_remove_output_pid(JNIEnv *env, jobject thiz,
    return tuner->removeOutputPid(pid);
}

static jobjectArray android_media_tv_Tuner_get_frontend_status_readiness(JNIEnv *env, jobject thiz,
                                                                         jintArray types) {
    sp<JTuner> tuner = getTuner(env, thiz);
    return tuner->getFrontendStatusReadiness(types);
}

static jint android_media_tv_Tuner_close_frontend(JNIEnv* env, jobject thiz, jint /* handle */) {
    sp<JTuner> tuner = getTuner(env, thiz);
    return tuner->closeFrontend();
@@ -4710,6 +4746,9 @@ static const JNINativeMethod gTunerMethods[] = {
            (void *)android_media_tv_Tuner_get_maximum_frontends },
    { "nativeRemoveOutputPid", "(I)I",
            (void *)android_media_tv_Tuner_remove_output_pid },
    { "nativeGetFrontendStatusReadiness",
            "([I)[Landroid/media/tv/tuner/frontend/FrontendStatusReadiness;",
            (void *)android_media_tv_Tuner_get_frontend_status_readiness },
};

static const JNINativeMethod gFilterMethods[] = {
+1 −0
Original line number Diff line number Diff line
@@ -206,6 +206,7 @@ struct JTuner : public RefBase {
    jint setMaxNumberOfFrontends(int32_t frontendType, int32_t maxNumber);
    int32_t getMaxNumberOfFrontends(int32_t frontendType);
    jint removeOutputPid(int32_t pid);
    jobjectArray getFrontendStatusReadiness(jintArray types);

    jweak getObject();

Loading