From 1faccac7730f0a002c1afe794f3bee00cd2df38e Mon Sep 17 00:00:00 2001 From: Tomasz Wasilczyk Date: Wed, 4 Apr 2018 11:15:51 -0700 Subject: [PATCH] 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 --- services/core/jni/BroadcastRadio/Tuner.cpp | 26 +++++++++++++++----------- services/core/jni/BroadcastRadio/convert.cpp | 4 ---- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/services/core/jni/BroadcastRadio/Tuner.cpp b/services/core/jni/BroadcastRadio/Tuner.cpp index 36d2994898c1..a04697fa4cd9 100644 --- a/services/core/jni/BroadcastRadio/Tuner.cpp +++ b/services/core/jni/BroadcastRadio/Tuner.cpp @@ -90,11 +90,12 @@ struct TunerContext { bool mIsAudioConnected = false; Band mBand; wp mHalModule; - wp mHalModule11; sp mHalTuner; sp mHalTuner11; sp mHalDeathRecipient; + sp getHalModule11() const; + private: DISALLOW_COPY_AND_ASSIGN(TunerContext); }; @@ -143,6 +144,16 @@ void HalDeathRecipient::serviceDied(uint64_t cookie __unused, tunerCallback->hardwareFailure(); } +sp 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 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 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 jRawImage = nullptr; auto hidlResult = halModule->getImage(id, [&](hidl_vec 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) { diff --git a/services/core/jni/BroadcastRadio/convert.cpp b/services/core/jni/BroadcastRadio/convert.cpp index 61b48c2e9316..d2b7c7d555ec 100644 --- a/services/core/jni/BroadcastRadio/convert.cpp +++ b/services/core/jni/BroadcastRadio/convert.cpp @@ -510,19 +510,16 @@ JavaRef MetadataFromHal(JNIEnv *env, const hidl_vec &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 MetadataFromHal(JNIEnv *env, const hidl_vec &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); -- 2.11.0