Merge "Add isLnaSupported API"

This commit is contained in:
Hongguang Chen
2022-11-29 16:57:38 +00:00
committed by Android (Google) Code Review
6 changed files with 56 additions and 1 deletions

View File

@@ -7269,6 +7269,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);

View File

@@ -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) {

View File

@@ -1819,6 +1819,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;
@@ -3562,6 +3569,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);
@@ -4810,6 +4822,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 },

View File

@@ -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);

View File

@@ -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

View File

@@ -148,6 +148,11 @@ public:
*/
int getMaxNumberOfFrontends(FrontendType frontendType);
/**
* Is Low Noise Amplifier (LNA) supported.
*/
bool isLnaSupported();
private:
/**
* An AIDL Tuner Service assigned at the first time the Tuner Client connects with