From afe95a99783156c3d84a67209d0c30d3e11f94e0 Mon Sep 17 00:00:00 2001 From: Steven Moreland Date: Tue, 23 May 2017 12:45:16 -0700 Subject: [PATCH] HIDL: C++ Java parity Add same restrictions to Java that we have in C++ HIDL code for C++ services. Test: hidl_test_java, multiple internal devices work Bug: 38415912 Change-Id: I48571a5cd94b0ba6b1f722d032e45aac6e9527ed --- core/jni/Android.bp | 9 +++++++++ core/jni/android_os_HwBinder.cpp | 17 +++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/core/jni/Android.bp b/core/jni/Android.bp index c8784f857ea79..a5f7d4f60470e 100644 --- a/core/jni/Android.bp +++ b/core/jni/Android.bp @@ -282,4 +282,13 @@ cc_library_shared { // GraphicsJNI.h includes hwui headers "libhwui", ], + + product_variables: { + debuggable: { + cflags: ["-D__ANDROID_DEBUGGABLE__"] + }, + treble: { + cflags: ["-D__ANDROID_TREBLE__"] + }, + }, } diff --git a/core/jni/android_os_HwBinder.cpp b/core/jni/android_os_HwBinder.cpp index 577cd49cbaec5..b5c881537c41a 100644 --- a/core/jni/android_os_HwBinder.cpp +++ b/core/jni/android_os_HwBinder.cpp @@ -23,6 +23,8 @@ #include "android_os_HwParcel.h" #include "android_os_HwRemoteBinder.h" +#include + #include #include #include @@ -329,8 +331,19 @@ static jobject JHwBinder_native_getService( IServiceManager::Transport transport = transportRet; - if ( transport != IServiceManager::Transport::EMPTY - && transport != IServiceManager::Transport::HWBINDER) { +#ifdef __ANDROID_TREBLE__ +#ifdef __ANDROID_DEBUGGABLE__ + const char* testingOverride = std::getenv("TREBLE_TESTING_OVERRIDE"); + const bool vintfLegacy = (transport == IServiceManager::Transport::EMPTY) + && testingOverride && !strcmp(testingOverride, "true"); +#else // __ANDROID_TREBLE__ but not __ANDROID_DEBUGGABLE__ + const bool vintfLegacy = false; +#endif // __ANDROID_DEBUGGABLE__ +#else // not __ANDROID_TREBLE__ + const bool vintfLegacy = (transport == IServiceManager::Transport::EMPTY); +#endif // __ANDROID_TREBLE__"; + + if (transport != IServiceManager::Transport::HWBINDER && !vintfLegacy) { LOG(ERROR) << "service " << ifaceName << " declares transport method " << toString(transport) << " but framework expects hwbinder."; signalExceptionForError(env, UNKNOWN_ERROR, true /* canThrowRemoteException */);