diff --git a/core/jni/android_os_HwBinder.cpp b/core/jni/android_os_HwBinder.cpp index 42e3942eb3506..9c60e6bd85651 100644 --- a/core/jni/android_os_HwBinder.cpp +++ b/core/jni/android_os_HwBinder.cpp @@ -224,6 +224,21 @@ status_t JHwBinder::onTransact( return err; } +bool validateCanUseHwBinder(const sp& binder) { + if (binder != nullptr && binder->localBinder() != nullptr) { + // untested/unsupported/inefficient + // see b/129150021, doesn't work with scatter-gather + // + // explicitly disabling until it is supported + // (note, even if this is fixed to work with scatter gather, we would also need + // to convert this to the Java object rather than re-wrapping with a proxy) + LOG(ERROR) << "Local Java Binder not supported."; + return false; + } + + return true; +} + } // namespace android //////////////////////////////////////////////////////////////////////////////// @@ -324,9 +339,9 @@ static jobject JHwBinder_native_getService( sp ret = getRawServiceInternal(ifaceName, serviceName, retry /* retry */, false /* getStub */); sp service = hardware::toBinder(ret); - if (service == NULL) { + if (service == nullptr || !validateCanUseHwBinder(service)) { signalExceptionForError(env, NAME_NOT_FOUND); - return NULL; + return nullptr; } LOG(INFO) << "HwBinder: Starting thread pool for getting: " << ifaceName << "/" << serviceName; diff --git a/core/jni/android_os_HwBinder.h b/core/jni/android_os_HwBinder.h index 5352f1e607c29..99195b1abc9c6 100644 --- a/core/jni/android_os_HwBinder.h +++ b/core/jni/android_os_HwBinder.h @@ -54,6 +54,8 @@ private: int register_android_os_HwBinder(JNIEnv *env); +bool validateCanUseHwBinder(const sp& binder); + } // namespace android #endif // _ANDROID_OS_HW_BINDER_H diff --git a/core/jni/android_os_HwParcel.cpp b/core/jni/android_os_HwParcel.cpp index 7221ca11cc00a..f437a78e35f86 100644 --- a/core/jni/android_os_HwParcel.cpp +++ b/core/jni/android_os_HwParcel.cpp @@ -883,8 +883,12 @@ static jobject JHwParcel_native_readStrongBinder(JNIEnv *env, jobject thiz) { sp binder = parcel->readStrongBinder(); - if (binder == NULL) { - return NULL; + if (binder == nullptr) { + return nullptr; + } + + if (!validateCanUseHwBinder(binder)) { + return nullptr; } return JHwRemoteBinder::NewObject(env, binder);