OSDN Git Service

HIDL Java getService now the same as C++.
authorSteven Moreland <smoreland@google.com>
Mon, 23 Oct 2017 07:09:33 +0000 (00:09 -0700)
committerSteven Moreland <smoreland@google.com>
Mon, 23 Oct 2017 08:23:45 +0000 (01:23 -0700)
getService: wait for service if it is declared in the manifest
tryGetService: only return if the service is immediately available

Bug: 67981006
Test: hidl_test_java
Change-Id: I4485b84f0fde98851cf5f64d198a8c5410795c8c

core/java/android/os/HwBinder.java
core/jni/android_os_HwBinder.cpp

index 270e63f..c1c65ff 100644 (file)
@@ -48,7 +48,8 @@ public abstract class HwBinder implements IHwBinder {
 
     public static native final IHwBinder getService(
             String iface,
-            String serviceName)
+            String serviceName,
+            boolean isTry)
         throws RemoteException, NoSuchElementException;
 
     public static native final void configureRpcThreadpool(
index fe14d48..7fd97b2 100644 (file)
@@ -303,7 +303,8 @@ static jobject JHwBinder_native_getService(
         JNIEnv *env,
         jclass /* clazzObj */,
         jstring ifaceNameObj,
-        jstring serviceNameObj) {
+        jstring serviceNameObj,
+        jboolean isTry) {
 
     using ::android::hidl::base::V1_0::IBase;
     using ::android::hardware::details::getRawServiceInternal;
@@ -331,8 +332,7 @@ static jobject JHwBinder_native_getService(
     std::string serviceName(serviceNameCStr);
     env->ReleaseStringUTFChars(serviceNameObj, serviceNameCStr);
 
-    // TODO(b/67981006): true /* retry */
-    sp<IBase> ret = getRawServiceInternal(ifaceName, serviceName, false /* retry */, false /* getStub */); 
+    sp<IBase> ret = getRawServiceInternal(ifaceName, serviceName, !isTry /* retry */, false /* getStub */);
     sp<hardware::IBinder> service = hardware::toBinder<hidl::base::V1_0::IBase>(ret);
 
     if (service == NULL) {
@@ -371,7 +371,7 @@ static JNINativeMethod gMethods[] = {
     { "registerService", "(Ljava/lang/String;)V",
         (void *)JHwBinder_native_registerService },
 
-    { "getService", "(Ljava/lang/String;Ljava/lang/String;)L" PACKAGE_PATH "/IHwBinder;",
+    { "getService", "(Ljava/lang/String;Ljava/lang/String;Z)L" PACKAGE_PATH "/IHwBinder;",
         (void *)JHwBinder_native_getService },
 
     { "configureRpcThreadpool", "(JZ)V",