From c4bfdefdca503b15485385c1187c2b3f641969d1 Mon Sep 17 00:00:00 2001 From: Steven Moreland Date: Wed, 18 Oct 2017 23:19:43 -0700 Subject: [PATCH] HwBinder: don't re-implement libhidl's getService Rather than re-implementing getService in the JNI backend for HIDL Java classes, we call the implementation in libhidl. This does several good things: - prevents frameworks/base/core from depending on PRODUCT_FULL_TREBLE - prevents frameworks/base/core from having any user vs. userdebug differences - ensures there are no subtle differences between C++ and Java getService - removes essentially copy/pasted code - unlocks the door to provide 'getService' 'tryGetService' semantics in Java (b/67981006) Has the side effect of making passthrough mode kind work in Java, but still with parcelling to transition between the ABIs: - getRawServiceInternal returns passthrough service - toBinder wraps that service in Bn* - in-process binder calls are made in the same process Test: device boots + hidl_test_java Bug: 67974907 Change-Id: Ie459f95eb8a059f578f703d1f73ca42417cfeeb8 --- core/jni/Android.bp | 9 ------- core/jni/android_os_HwBinder.cpp | 57 +++------------------------------------- 2 files changed, 3 insertions(+), 63 deletions(-) diff --git a/core/jni/Android.bp b/core/jni/Android.bp index c5279e10d93f..9258f0fef20a 100644 --- a/core/jni/Android.bp +++ b/core/jni/Android.bp @@ -291,13 +291,4 @@ 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 59ca050a23e1..fe14d483743f 100644 --- a/core/jni/android_os_HwBinder.cpp +++ b/core/jni/android_os_HwBinder.cpp @@ -306,7 +306,7 @@ static jobject JHwBinder_native_getService( jstring serviceNameObj) { using ::android::hidl::base::V1_0::IBase; - using ::android::hidl::manager::V1_0::IServiceManager; + using ::android::hardware::details::getRawServiceInternal; if (ifaceNameObj == NULL) { jniThrowException(env, "java/lang/NullPointerException", NULL); @@ -317,22 +317,12 @@ static jobject JHwBinder_native_getService( return NULL; } - auto manager = hardware::defaultServiceManager(); - - if (manager == nullptr) { - LOG(ERROR) << "Could not get hwservicemanager."; - signalExceptionForError(env, UNKNOWN_ERROR, true /* canThrowRemoteException */); - return NULL; - } - const char *ifaceNameCStr = env->GetStringUTFChars(ifaceNameObj, NULL); if (ifaceNameCStr == NULL) { return NULL; // XXX exception already pending? } std::string ifaceName(ifaceNameCStr); env->ReleaseStringUTFChars(ifaceNameObj, ifaceNameCStr); - ::android::hardware::hidl_string ifaceNameHStr; - ifaceNameHStr.setToExternal(ifaceName.c_str(), ifaceName.size()); const char *serviceNameCStr = env->GetStringUTFChars(serviceNameObj, NULL); if (serviceNameCStr == NULL) { @@ -340,50 +330,9 @@ static jobject JHwBinder_native_getService( } std::string serviceName(serviceNameCStr); env->ReleaseStringUTFChars(serviceNameObj, serviceNameCStr); - ::android::hardware::hidl_string serviceNameHStr; - serviceNameHStr.setToExternal(serviceName.c_str(), serviceName.size()); - - LOG(INFO) << "Looking for service " - << ifaceName - << "/" - << serviceName; - - Return transportRet = - manager->getTransport(ifaceNameHStr, serviceNameHStr); - - if (!transportRet.isOk()) { - signalExceptionForError(env, UNKNOWN_ERROR, true /* canThrowRemoteException */); - return NULL; - } - - IServiceManager::Transport transport = transportRet; - -#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, NAME_NOT_FOUND, true /* canThrowRemoteException */); - return NULL; - } - - Return> ret = manager->get(ifaceNameHStr, serviceNameHStr); - - if (!ret.isOk()) { - signalExceptionForError(env, UNKNOWN_ERROR, true /* canThrowRemoteException */); - return NULL; - } + // TODO(b/67981006): true /* retry */ + sp ret = getRawServiceInternal(ifaceName, serviceName, false /* retry */, false /* getStub */); sp service = hardware::toBinder(ret); if (service == NULL) { -- 2.11.0