Merge "HwBinder: get/register checked exceptions."
am: 9ec4fec5ca
Change-Id: Id6abc10992428af2e55cb5228c298b69c111c621
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
package android.os;
|
package android.os;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
import libcore.util.NativeAllocationRegistry;
|
import libcore.util.NativeAllocationRegistry;
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
@@ -44,11 +45,13 @@ public abstract class HwBinder implements IHwBinder {
|
|||||||
|
|
||||||
public native final void registerService(
|
public native final void registerService(
|
||||||
ArrayList<String> interfaceChain,
|
ArrayList<String> interfaceChain,
|
||||||
String serviceName);
|
String serviceName)
|
||||||
|
throws RemoteException;
|
||||||
|
|
||||||
public static native final IHwBinder getService(
|
public static native final IHwBinder getService(
|
||||||
String iface,
|
String iface,
|
||||||
String serviceName);
|
String serviceName)
|
||||||
|
throws RemoteException, NoSuchElementException;
|
||||||
|
|
||||||
// Returns address of the "freeFunction".
|
// Returns address of the "freeFunction".
|
||||||
private static native final long native_init();
|
private static native final long native_init();
|
||||||
|
|||||||
@@ -37,6 +37,5 @@ public interface IHwBinder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean linkToDeath(DeathRecipient recipient, long cookie);
|
public boolean linkToDeath(DeathRecipient recipient, long cookie);
|
||||||
|
|
||||||
public boolean unlinkToDeath(DeathRecipient recipient);
|
public boolean unlinkToDeath(DeathRecipient recipient);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,8 @@
|
|||||||
using android::AndroidRuntime;
|
using android::AndroidRuntime;
|
||||||
using android::hardware::hidl_vec;
|
using android::hardware::hidl_vec;
|
||||||
using android::hardware::hidl_string;
|
using android::hardware::hidl_string;
|
||||||
|
template<typename T>
|
||||||
|
using Return = android::hardware::Return<T>;
|
||||||
|
|
||||||
#define PACKAGE_PATH "android/os"
|
#define PACKAGE_PATH "android/os"
|
||||||
#define CLASS_NAME "HwBinder"
|
#define CLASS_NAME "HwBinder"
|
||||||
@@ -257,8 +259,6 @@ static void JHwBinder_native_registerService(
|
|||||||
hidl_vec<hidl_string> interfaceChain;
|
hidl_vec<hidl_string> interfaceChain;
|
||||||
interfaceChain.setToExternal(strings, numInterfaces, true /* shouldOwn */);
|
interfaceChain.setToExternal(strings, numInterfaces, true /* shouldOwn */);
|
||||||
|
|
||||||
using android::hidl::manager::V1_0::IServiceManager;
|
|
||||||
|
|
||||||
sp<hardware::IBinder> binder = JHwBinder::GetNativeContext(env, thiz);
|
sp<hardware::IBinder> binder = JHwBinder::GetNativeContext(env, thiz);
|
||||||
|
|
||||||
/* TODO(b/33440494) this is not right */
|
/* TODO(b/33440494) this is not right */
|
||||||
@@ -268,24 +268,23 @@ static void JHwBinder_native_registerService(
|
|||||||
|
|
||||||
if (manager == nullptr) {
|
if (manager == nullptr) {
|
||||||
LOG(ERROR) << "Could not get hwservicemanager.";
|
LOG(ERROR) << "Could not get hwservicemanager.";
|
||||||
signalExceptionForError(env, UNKNOWN_ERROR);
|
signalExceptionForError(env, UNKNOWN_ERROR, true /* canThrowRemoteException */);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ok = manager->add(
|
Return<bool> ret = manager->add(interfaceChain, serviceName, base);
|
||||||
interfaceChain,
|
|
||||||
serviceName,
|
|
||||||
base);
|
|
||||||
|
|
||||||
env->ReleaseStringUTFChars(serviceNameObj, serviceName);
|
env->ReleaseStringUTFChars(serviceNameObj, serviceName);
|
||||||
serviceName = NULL;
|
serviceName = NULL;
|
||||||
|
|
||||||
|
bool ok = ret.isOk() && ret;
|
||||||
|
|
||||||
if (ok) {
|
if (ok) {
|
||||||
LOG(INFO) << "Starting thread pool.";
|
LOG(INFO) << "Starting thread pool.";
|
||||||
::android::hardware::ProcessState::self()->startThreadPool();
|
::android::hardware::ProcessState::self()->startThreadPool();
|
||||||
}
|
}
|
||||||
|
|
||||||
signalExceptionForError(env, (ok ? OK : UNKNOWN_ERROR));
|
signalExceptionForError(env, (ok ? OK : UNKNOWN_ERROR), true /* canThrowRemoteException */);
|
||||||
}
|
}
|
||||||
|
|
||||||
static jobject JHwBinder_native_getService(
|
static jobject JHwBinder_native_getService(
|
||||||
@@ -321,13 +320,18 @@ static jobject JHwBinder_native_getService(
|
|||||||
|
|
||||||
if (manager == nullptr) {
|
if (manager == nullptr) {
|
||||||
LOG(ERROR) << "Could not get hwservicemanager.";
|
LOG(ERROR) << "Could not get hwservicemanager.";
|
||||||
signalExceptionForError(env, UNKNOWN_ERROR);
|
signalExceptionForError(env, UNKNOWN_ERROR, true /* canThrowRemoteException */);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
sp<hidl::base::V1_0::IBase> base = manager->get(ifaceName, serviceName);
|
Return<sp<hidl::base::V1_0::IBase>> ret = manager->get(ifaceName, serviceName);
|
||||||
|
|
||||||
|
if (!ret.isOk()) {
|
||||||
|
signalExceptionForError(env, UNKNOWN_ERROR, true /* canThrowRemoteException */);
|
||||||
|
}
|
||||||
|
|
||||||
sp<hardware::IBinder> service = hardware::toBinder<
|
sp<hardware::IBinder> 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);
|
env->ReleaseStringUTFChars(ifaceNameObj, ifaceName);
|
||||||
ifaceName = NULL;
|
ifaceName = NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user