Merge "Adds support for specifying the version of a service to register/lookup."

This commit is contained in:
Andreas Huber
2016-10-26 15:38:44 +00:00
committed by Gerrit Code Review
2 changed files with 37 additions and 8 deletions

View File

@@ -38,8 +38,11 @@ public abstract class HwBinder implements IHwBinder {
public abstract void onTransact(
int code, HwParcel request, HwParcel reply, int flags);
public native final void registerService(String serviceName);
public static native final IHwBinder getService(String serviceName);
public native final void registerService(
String serviceName, int versionMajor, int versionMinor);
public static native final IHwBinder getService(
String serviceName, int versionMajor, int versionMinor);
// Returns address of the "freeFunction".
private static native final long native_init();

View File

@@ -196,19 +196,32 @@ static void JHwBinder_native_transact(
}
static void JHwBinder_native_registerService(
JNIEnv *env, jobject thiz, jstring serviceNameObj) {
JNIEnv *env,
jobject thiz,
jstring serviceNameObj,
jint versionMajor,
jint versionMinor) {
if (serviceNameObj == NULL) {
jniThrowException(env, "java/lang/NullPointerException", NULL);
return;
}
if (versionMajor < 0
|| versionMajor > 65535
|| versionMinor < 0
|| versionMinor > 65535) {
jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
return;
}
const jchar *serviceName = env->GetStringCritical(serviceNameObj, NULL);
if (serviceName == NULL) {
return; // XXX exception already pending?
}
const hardware::hidl_version kVersion = hardware::make_hidl_version(1, 0);
const hardware::hidl_version kVersion =
hardware::make_hidl_version(versionMajor, versionMinor);
sp<hardware::IBinder> binder = JHwBinder::GetNativeContext(env, thiz);
@@ -231,19 +244,32 @@ static void JHwBinder_native_registerService(
}
static jobject JHwBinder_native_getService(
JNIEnv *env, jclass /* clazzObj */, jstring serviceNameObj) {
JNIEnv *env,
jclass /* clazzObj */,
jstring serviceNameObj,
jint versionMajor,
jint versionMinor) {
if (serviceNameObj == NULL) {
jniThrowException(env, "java/lang/NullPointerException", NULL);
return NULL;
}
if (versionMajor < 0
|| versionMajor > 65535
|| versionMinor < 0
|| versionMinor > 65535) {
jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
return NULL;
}
const jchar *serviceName = env->GetStringCritical(serviceNameObj, NULL);
if (serviceName == NULL) {
return NULL; // XXX exception already pending?
}
const hardware::hidl_version kVersion = hardware::make_hidl_version(1, 0);
const hardware::hidl_version kVersion =
hardware::make_hidl_version(versionMajor, versionMinor);
LOG(INFO) << "looking for service '"
<< String8(String16(
@@ -280,10 +306,10 @@ static JNINativeMethod gMethods[] = {
"(IL" PACKAGE_PATH "/HwParcel;L" PACKAGE_PATH "/HwParcel;I)V",
(void *)JHwBinder_native_transact },
{ "registerService", "(Ljava/lang/String;)V",
{ "registerService", "(Ljava/lang/String;II)V",
(void *)JHwBinder_native_registerService },
{ "getService", "(Ljava/lang/String;)L" PACKAGE_PATH "/IHwBinder;",
{ "getService", "(Ljava/lang/String;II)L" PACKAGE_PATH "/IHwBinder;",
(void *)JHwBinder_native_getService },
};