Fix image fetching.
Also, while we're here, reduce logs verbosity.
Test: open car.Media app with radio service selected, tune to a station
(requires a patch with image support against radio app)
Bug: 75970985
Change-Id: I4e56dcdc8bacbb5e63f67eba4a0b0a126245b415
This commit is contained in:
@@ -90,11 +90,12 @@ struct TunerContext {
|
||||
bool mIsAudioConnected = false;
|
||||
Band mBand;
|
||||
wp<V1_0::IBroadcastRadio> mHalModule;
|
||||
wp<V1_1::IBroadcastRadio> mHalModule11;
|
||||
sp<V1_0::ITuner> mHalTuner;
|
||||
sp<V1_1::ITuner> mHalTuner11;
|
||||
sp<HalDeathRecipient> mHalDeathRecipient;
|
||||
|
||||
sp<V1_1::IBroadcastRadio> getHalModule11() const;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(TunerContext);
|
||||
};
|
||||
@@ -143,6 +144,16 @@ void HalDeathRecipient::serviceDied(uint64_t cookie __unused,
|
||||
tunerCallback->hardwareFailure();
|
||||
}
|
||||
|
||||
sp<V1_1::IBroadcastRadio> TunerContext::getHalModule11() const {
|
||||
auto halModule = mHalModule.promote();
|
||||
if (halModule == nullptr) {
|
||||
ALOGE("HAL module is gone");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return V1_1::IBroadcastRadio::castFrom(halModule).withDefault(nullptr);
|
||||
}
|
||||
|
||||
// TODO(b/62713378): implement support for multiple tuners open at the same time
|
||||
static void notifyAudioService(TunerContext& ctx, bool connected) {
|
||||
if (!ctx.mWithAudio) return;
|
||||
@@ -175,8 +186,6 @@ void assignHalInterfaces(JNIEnv *env, JavaRef<jobject> const &jTuner,
|
||||
}
|
||||
|
||||
ctx.mHalModule = halModule;
|
||||
ctx.mHalModule11 = V1_1::IBroadcastRadio::castFrom(halModule).withDefault(nullptr);
|
||||
|
||||
ctx.mHalTuner = halTuner;
|
||||
ctx.mHalTuner11 = V1_1::ITuner::castFrom(halTuner).withDefault(nullptr);
|
||||
ALOGW_IF(ctx.mHalRev >= HalRevision::V1_1 && ctx.mHalTuner11 == nullptr,
|
||||
@@ -388,18 +397,13 @@ static jbyteArray nativeGetImage(JNIEnv *env, jobject obj, jlong nativeContext,
|
||||
lock_guard<mutex> lk(gContextMutex);
|
||||
auto& ctx = getNativeContext(nativeContext);
|
||||
|
||||
if (ctx.mHalModule11 == nullptr) {
|
||||
auto halModule = ctx.getHalModule11();
|
||||
if (halModule == nullptr) {
|
||||
jniThrowException(env, "java/lang/IllegalStateException",
|
||||
"Out-of-band images are not supported with HAL < 1.1");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto halModule = ctx.mHalModule11.promote();
|
||||
if (halModule == nullptr) {
|
||||
ALOGE("HAL module is gone");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
JavaRef<jbyteArray> jRawImage = nullptr;
|
||||
|
||||
auto hidlResult = halModule->getImage(id, [&](hidl_vec<uint8_t> rawImage) {
|
||||
@@ -418,7 +422,7 @@ static jbyteArray nativeGetImage(JNIEnv *env, jobject obj, jlong nativeContext,
|
||||
|
||||
if (convert::ThrowIfFailed(env, hidlResult)) return nullptr;
|
||||
|
||||
return jRawImage.get();
|
||||
return jRawImage.release();
|
||||
}
|
||||
|
||||
static bool nativeIsAnalogForced(JNIEnv *env, jobject obj, jlong nativeContext) {
|
||||
|
||||
@@ -510,19 +510,16 @@ JavaRef<jobject> MetadataFromHal(JNIEnv *env, const hidl_vec<V1_0::MetaData> &me
|
||||
jint status = 0;
|
||||
switch (item.type) {
|
||||
case MetadataType::INT:
|
||||
ALOGV("metadata INT %d", key);
|
||||
status = env->CallIntMethod(jMetadata.get(), gjni.RadioMetadata.putIntFromNative,
|
||||
key, item.intValue);
|
||||
break;
|
||||
case MetadataType::TEXT: {
|
||||
ALOGV("metadata TEXT %d", key);
|
||||
auto value = make_javastr(env, item.stringValue);
|
||||
status = env->CallIntMethod(jMetadata.get(), gjni.RadioMetadata.putStringFromNative,
|
||||
key, value.get());
|
||||
break;
|
||||
}
|
||||
case MetadataType::RAW: {
|
||||
ALOGV("metadata RAW %d", key);
|
||||
auto len = item.rawValue.size();
|
||||
if (len == 0) break;
|
||||
auto value = make_javaref(env, env->NewByteArray(len));
|
||||
@@ -537,7 +534,6 @@ JavaRef<jobject> MetadataFromHal(JNIEnv *env, const hidl_vec<V1_0::MetaData> &me
|
||||
break;
|
||||
}
|
||||
case MetadataType::CLOCK:
|
||||
ALOGV("metadata CLOCK %d", key);
|
||||
status = env->CallIntMethod(jMetadata.get(), gjni.RadioMetadata.putClockFromNative,
|
||||
key, item.clockValue.utcSecondsSinceEpoch,
|
||||
item.clockValue.timezoneOffsetInMinutes);
|
||||
|
||||
Reference in New Issue
Block a user