From: Steven Moreland Date: Wed, 4 Jan 2017 18:37:59 +0000 (-0800) Subject: HwBinder: get/register checked exceptions. X-Git-Tag: android-x86-8.1-r1~5809^2 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=20ca2f782bb1eddba3e77051e030a7df60750b81;p=android-x86%2Fframeworks-base.git HwBinder: get/register checked exceptions. Bug: 33673120 Test: hidl_test_java Change-Id: Id19b61b252e756a032ae11f7b59bd8eed82edbe9 --- diff --git a/core/java/android/os/HwBinder.java b/core/java/android/os/HwBinder.java index bcc3468724fd..e02549426cb5 100644 --- a/core/java/android/os/HwBinder.java +++ b/core/java/android/os/HwBinder.java @@ -17,6 +17,7 @@ package android.os; import java.util.ArrayList; +import java.util.NoSuchElementException; import libcore.util.NativeAllocationRegistry; /** @hide */ @@ -44,11 +45,13 @@ public abstract class HwBinder implements IHwBinder { public native final void registerService( ArrayList interfaceChain, - String serviceName); + String serviceName) + throws RemoteException; public static native final IHwBinder getService( String iface, - String serviceName); + String serviceName) + throws RemoteException, NoSuchElementException; // Returns address of the "freeFunction". private static native final long native_init(); diff --git a/core/java/android/os/IHwBinder.java b/core/java/android/os/IHwBinder.java index 2a6567989ced..619f4dc631d5 100644 --- a/core/java/android/os/IHwBinder.java +++ b/core/java/android/os/IHwBinder.java @@ -37,6 +37,5 @@ public interface IHwBinder { } public boolean linkToDeath(DeathRecipient recipient, long cookie); - public boolean unlinkToDeath(DeathRecipient recipient); } diff --git a/core/jni/android_os_HwBinder.cpp b/core/jni/android_os_HwBinder.cpp index 81199fa41e1b..20bb885eb578 100644 --- a/core/jni/android_os_HwBinder.cpp +++ b/core/jni/android_os_HwBinder.cpp @@ -39,6 +39,8 @@ using android::AndroidRuntime; using android::hardware::hidl_vec; using android::hardware::hidl_string; +template +using Return = android::hardware::Return; #define PACKAGE_PATH "android/os" #define CLASS_NAME "HwBinder" @@ -257,8 +259,6 @@ static void JHwBinder_native_registerService( hidl_vec interfaceChain; interfaceChain.setToExternal(strings, numInterfaces, true /* shouldOwn */); - using android::hidl::manager::V1_0::IServiceManager; - sp binder = JHwBinder::GetNativeContext(env, thiz); /* TODO(b/33440494) this is not right */ @@ -268,24 +268,23 @@ static void JHwBinder_native_registerService( if (manager == nullptr) { LOG(ERROR) << "Could not get hwservicemanager."; - signalExceptionForError(env, UNKNOWN_ERROR); + signalExceptionForError(env, UNKNOWN_ERROR, true /* canThrowRemoteException */); return; } - bool ok = manager->add( - interfaceChain, - serviceName, - base); + Return ret = manager->add(interfaceChain, serviceName, base); env->ReleaseStringUTFChars(serviceNameObj, serviceName); serviceName = NULL; + bool ok = ret.isOk() && ret; + if (ok) { LOG(INFO) << "Starting thread pool."; ::android::hardware::ProcessState::self()->startThreadPool(); } - signalExceptionForError(env, (ok ? OK : UNKNOWN_ERROR)); + signalExceptionForError(env, (ok ? OK : UNKNOWN_ERROR), true /* canThrowRemoteException */); } static jobject JHwBinder_native_getService( @@ -321,13 +320,18 @@ static jobject JHwBinder_native_getService( if (manager == nullptr) { LOG(ERROR) << "Could not get hwservicemanager."; - signalExceptionForError(env, UNKNOWN_ERROR); + signalExceptionForError(env, UNKNOWN_ERROR, true /* canThrowRemoteException */); return NULL; } - sp base = manager->get(ifaceName, serviceName); + Return> ret = manager->get(ifaceName, serviceName); + + if (!ret.isOk()) { + signalExceptionForError(env, UNKNOWN_ERROR, true /* canThrowRemoteException */); + } + sp service = hardware::toBinder< - hidl::base::V1_0::IBase, hidl::base::V1_0::BpBase>(base); + hidl::base::V1_0::IBase, hidl::base::V1_0::BpBase>(ret); env->ReleaseStringUTFChars(ifaceNameObj, ifaceName); ifaceName = NULL;