Merge "Fix basic broadcastradio HAL 1.1/2.0 functionality." into pi-dev

This commit is contained in:
Tomasz Wasilczyk
2018-03-08 19:44:04 +00:00
committed by Android (Google) Code Review
5 changed files with 45 additions and 2 deletions

View File

@@ -441,6 +441,15 @@ public final class ProgramSelector implements Parcelable {
*/ */
public static @NonNull ProgramSelector createAmFmSelector( public static @NonNull ProgramSelector createAmFmSelector(
@RadioManager.Band int band, int frequencyKhz, int subChannel) { @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 isAm = (band == RadioManager.BAND_AM || band == RadioManager.BAND_AM_HD);
boolean isDigital = (band == RadioManager.BAND_AM_HD || band == RadioManager.BAND_FM_HD); boolean isDigital = (band == RadioManager.BAND_AM_HD || band == RadioManager.BAND_FM_HD);
if (!isAm && !isDigital && band != RadioManager.BAND_FM) { if (!isAm && !isDigital && band != RadioManager.BAND_FM) {

View File

@@ -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 @Override
public void setConfiguration(RadioManager.BandConfig config) { public void setConfiguration(RadioManager.BandConfig config) {
if (config == null) { if (config == null) {
@@ -170,6 +176,7 @@ class Tuner extends ITuner.Stub {
public void step(boolean directionDown, boolean skipSubChannel) { public void step(boolean directionDown, boolean skipSubChannel) {
synchronized (mLock) { synchronized (mLock) {
checkNotClosedLocked(); checkNotClosedLocked();
if (!checkConfiguredLocked()) return;
nativeStep(mNativeContext, directionDown, skipSubChannel); nativeStep(mNativeContext, directionDown, skipSubChannel);
} }
} }
@@ -178,6 +185,7 @@ class Tuner extends ITuner.Stub {
public void scan(boolean directionDown, boolean skipSubChannel) { public void scan(boolean directionDown, boolean skipSubChannel) {
synchronized (mLock) { synchronized (mLock) {
checkNotClosedLocked(); checkNotClosedLocked();
if (!checkConfiguredLocked()) return;
nativeScan(mNativeContext, directionDown, skipSubChannel); nativeScan(mNativeContext, directionDown, skipSubChannel);
} }
} }
@@ -190,6 +198,7 @@ class Tuner extends ITuner.Stub {
Slog.i(TAG, "Tuning to " + selector); Slog.i(TAG, "Tuning to " + selector);
synchronized (mLock) { synchronized (mLock) {
checkNotClosedLocked(); checkNotClosedLocked();
if (!checkConfiguredLocked()) return;
nativeTune(mNativeContext, selector); nativeTune(mNativeContext, selector);
} }
} }

View File

@@ -47,6 +47,7 @@ class TunerCallback implements ITunerCallback {
@NonNull private final ITunerCallback mClientCallback; @NonNull private final ITunerCallback mClientCallback;
private final AtomicReference<ProgramList.Filter> mProgramListFilter = new AtomicReference<>(); private final AtomicReference<ProgramList.Filter> mProgramListFilter = new AtomicReference<>();
private boolean mInitialConfigurationDone = false;
TunerCallback(@NonNull Tuner tuner, @NonNull ITunerCallback clientCallback, int halRev) { TunerCallback(@NonNull Tuner tuner, @NonNull ITunerCallback clientCallback, int halRev) {
mTuner = tuner; mTuner = tuner;
@@ -95,6 +96,10 @@ class TunerCallback implements ITunerCallback {
mProgramListFilter.set(null); mProgramListFilter.set(null);
} }
boolean isInitialConfigurationDone() {
return mInitialConfigurationDone;
}
@Override @Override
public void onError(int status) { public void onError(int status) {
dispatch(() -> mClientCallback.onError(status)); dispatch(() -> mClientCallback.onError(status));
@@ -107,6 +112,7 @@ class TunerCallback implements ITunerCallback {
@Override @Override
public void onConfigurationChanged(RadioManager.BandConfig config) { public void onConfigurationChanged(RadioManager.BandConfig config) {
mInitialConfigurationDone = true;
dispatch(() -> mClientCallback.onConfigurationChanged(config)); dispatch(() -> mClientCallback.onConfigurationChanged(config));
} }

View File

@@ -72,6 +72,7 @@ static struct {
struct Module { struct Module {
sp<V1_0::IBroadcastRadio> radioModule; sp<V1_0::IBroadcastRadio> radioModule;
HalRevision halRev; HalRevision halRev;
std::vector<hardware::broadcastradio::V1_0::BandConfig> bands;
}; };
struct ServiceContext { struct ServiceContext {
@@ -169,7 +170,8 @@ static jobject nativeLoadModules(JNIEnv *env, jobject obj, jlong nativeContext)
if (module10 == nullptr) continue; if (module10 == nullptr) continue;
auto idx = ctx.mModules.size(); 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)", ALOGI("loaded broadcast radio module %zu: %s:%s (HAL 1.%d)",
idx, serviceName.c_str(), V1_0::toString(clazz).c_str(), halMinor); 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; Return<void> hidlResult;
if (module11 != nullptr) { if (module11 != nullptr) {
hidlResult = module11->getProperties_1_1([&](const V1_1::Properties& properties) { hidlResult = module11->getProperties_1_1([&](const V1_1::Properties& properties) {
nModule.bands = properties.base.bands;
jModule = convert::ModulePropertiesFromHal(env, properties, idx, serviceName); jModule = convert::ModulePropertiesFromHal(env, properties, idx, serviceName);
}); });
} else { } else {
@@ -185,6 +188,7 @@ static jobject nativeLoadModules(JNIEnv *env, jobject obj, jlong nativeContext)
const V1_0::Properties& properties) { const V1_0::Properties& properties) {
halResult = result; halResult = result;
if (result != Result::OK) return; if (result != Result::OK) return;
nModule.bands = properties.bands;
jModule = convert::ModulePropertiesFromHal(env, properties, idx, serviceName); 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]; auto module = ctx.mModules[moduleId];
Region region; 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, auto tuner = make_javaref(env, env->NewObject(gjni.Tuner.clazz, gjni.Tuner.cstor,
callback, module.halRev, region, withAudio, bandConfigHal.type)); callback, module.halRev, region, withAudio, bandConfigHal.type));

View File

@@ -41,6 +41,7 @@ enum class Status : jint {
// Keep in sync with REGION_* constants from RadioManager.java. // Keep in sync with REGION_* constants from RadioManager.java.
enum class Region : jint { enum class Region : jint {
INVALID = -1,
ITU_1 = 0, ITU_1 = 0,
ITU_2 = 1, ITU_2 = 1,
OIRT = 2, OIRT = 2,