Merge "Fix basic broadcastradio HAL 1.1/2.0 functionality." into pi-dev
am: 8580671f55
Change-Id: I95183ddf4ba57eca5c8789035c5c7c6bf0c92123
This commit is contained in:
@@ -441,6 +441,15 @@ public final class ProgramSelector implements Parcelable {
|
||||
*/
|
||||
public static @NonNull ProgramSelector createAmFmSelector(
|
||||
@RadioManager.Band int band, int frequencyKhz, int subChannel) {
|
||||
if (band == RadioManager.BAND_INVALID) {
|
||||
// 50MHz is a rough boundary between AM (<30MHz) and FM (>60MHz).
|
||||
if (frequencyKhz < 50000) {
|
||||
band = (subChannel <= 0) ? RadioManager.BAND_AM : RadioManager.BAND_AM_HD;
|
||||
} else {
|
||||
band = (subChannel <= 0) ? RadioManager.BAND_FM : RadioManager.BAND_FM_HD;
|
||||
}
|
||||
}
|
||||
|
||||
boolean isAm = (band == RadioManager.BAND_AM || band == RadioManager.BAND_AM_HD);
|
||||
boolean isDigital = (band == RadioManager.BAND_AM_HD || band == RadioManager.BAND_FM_HD);
|
||||
if (!isAm && !isDigital && band != RadioManager.BAND_FM) {
|
||||
|
||||
@@ -120,6 +120,12 @@ class Tuner extends ITuner.Stub {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkConfiguredLocked() {
|
||||
if (mTunerCallback.isInitialConfigurationDone()) return true;
|
||||
Slog.w(TAG, "Initial configuration is still pending, skipping the operation");
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConfiguration(RadioManager.BandConfig config) {
|
||||
if (config == null) {
|
||||
@@ -170,6 +176,7 @@ class Tuner extends ITuner.Stub {
|
||||
public void step(boolean directionDown, boolean skipSubChannel) {
|
||||
synchronized (mLock) {
|
||||
checkNotClosedLocked();
|
||||
if (!checkConfiguredLocked()) return;
|
||||
nativeStep(mNativeContext, directionDown, skipSubChannel);
|
||||
}
|
||||
}
|
||||
@@ -178,6 +185,7 @@ class Tuner extends ITuner.Stub {
|
||||
public void scan(boolean directionDown, boolean skipSubChannel) {
|
||||
synchronized (mLock) {
|
||||
checkNotClosedLocked();
|
||||
if (!checkConfiguredLocked()) return;
|
||||
nativeScan(mNativeContext, directionDown, skipSubChannel);
|
||||
}
|
||||
}
|
||||
@@ -190,6 +198,7 @@ class Tuner extends ITuner.Stub {
|
||||
Slog.i(TAG, "Tuning to " + selector);
|
||||
synchronized (mLock) {
|
||||
checkNotClosedLocked();
|
||||
if (!checkConfiguredLocked()) return;
|
||||
nativeTune(mNativeContext, selector);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ class TunerCallback implements ITunerCallback {
|
||||
@NonNull private final ITunerCallback mClientCallback;
|
||||
|
||||
private final AtomicReference<ProgramList.Filter> mProgramListFilter = new AtomicReference<>();
|
||||
private boolean mInitialConfigurationDone = false;
|
||||
|
||||
TunerCallback(@NonNull Tuner tuner, @NonNull ITunerCallback clientCallback, int halRev) {
|
||||
mTuner = tuner;
|
||||
@@ -95,6 +96,10 @@ class TunerCallback implements ITunerCallback {
|
||||
mProgramListFilter.set(null);
|
||||
}
|
||||
|
||||
boolean isInitialConfigurationDone() {
|
||||
return mInitialConfigurationDone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(int status) {
|
||||
dispatch(() -> mClientCallback.onError(status));
|
||||
@@ -107,6 +112,7 @@ class TunerCallback implements ITunerCallback {
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(RadioManager.BandConfig config) {
|
||||
mInitialConfigurationDone = true;
|
||||
dispatch(() -> mClientCallback.onConfigurationChanged(config));
|
||||
}
|
||||
|
||||
|
||||
@@ -72,6 +72,7 @@ static struct {
|
||||
struct Module {
|
||||
sp<V1_0::IBroadcastRadio> radioModule;
|
||||
HalRevision halRev;
|
||||
std::vector<hardware::broadcastradio::V1_0::BandConfig> bands;
|
||||
};
|
||||
|
||||
struct ServiceContext {
|
||||
@@ -169,7 +170,8 @@ static jobject nativeLoadModules(JNIEnv *env, jobject obj, jlong nativeContext)
|
||||
if (module10 == nullptr) continue;
|
||||
|
||||
auto idx = ctx.mModules.size();
|
||||
ctx.mModules.push_back({module10, halRev});
|
||||
ctx.mModules.push_back({module10, halRev, {}});
|
||||
auto& nModule = ctx.mModules[idx];
|
||||
ALOGI("loaded broadcast radio module %zu: %s:%s (HAL 1.%d)",
|
||||
idx, serviceName.c_str(), V1_0::toString(clazz).c_str(), halMinor);
|
||||
|
||||
@@ -178,6 +180,7 @@ static jobject nativeLoadModules(JNIEnv *env, jobject obj, jlong nativeContext)
|
||||
Return<void> hidlResult;
|
||||
if (module11 != nullptr) {
|
||||
hidlResult = module11->getProperties_1_1([&](const V1_1::Properties& properties) {
|
||||
nModule.bands = properties.base.bands;
|
||||
jModule = convert::ModulePropertiesFromHal(env, properties, idx, serviceName);
|
||||
});
|
||||
} else {
|
||||
@@ -185,6 +188,7 @@ static jobject nativeLoadModules(JNIEnv *env, jobject obj, jlong nativeContext)
|
||||
const V1_0::Properties& properties) {
|
||||
halResult = result;
|
||||
if (result != Result::OK) return;
|
||||
nModule.bands = properties.bands;
|
||||
jModule = convert::ModulePropertiesFromHal(env, properties, idx, serviceName);
|
||||
});
|
||||
}
|
||||
@@ -217,7 +221,21 @@ static jobject nativeOpenTuner(JNIEnv *env, jobject obj, long nativeContext, jin
|
||||
auto module = ctx.mModules[moduleId];
|
||||
|
||||
Region region;
|
||||
BandConfig bandConfigHal = convert::BandConfigToHal(env, bandConfig, region);
|
||||
BandConfig bandConfigHal;
|
||||
if (bandConfig != nullptr) {
|
||||
bandConfigHal = convert::BandConfigToHal(env, bandConfig, region);
|
||||
} else {
|
||||
region = Region::INVALID;
|
||||
if (module.bands.size() == 0) {
|
||||
ALOGE("No bands defined");
|
||||
return nullptr;
|
||||
}
|
||||
bandConfigHal = module.bands[0];
|
||||
if (bandConfigHal.spacings.size() > 1) {
|
||||
bandConfigHal.spacings = hidl_vec<uint32_t>({ *std::min_element(
|
||||
bandConfigHal.spacings.begin(), bandConfigHal.spacings.end()) });
|
||||
}
|
||||
}
|
||||
|
||||
auto tuner = make_javaref(env, env->NewObject(gjni.Tuner.clazz, gjni.Tuner.cstor,
|
||||
callback, module.halRev, region, withAudio, bandConfigHal.type));
|
||||
|
||||
@@ -41,6 +41,7 @@ enum class Status : jint {
|
||||
|
||||
// Keep in sync with REGION_* constants from RadioManager.java.
|
||||
enum class Region : jint {
|
||||
INVALID = -1,
|
||||
ITU_1 = 0,
|
||||
ITU_2 = 1,
|
||||
OIRT = 2,
|
||||
|
||||
Reference in New Issue
Block a user