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( public abstract void onTransact(
int code, HwParcel request, HwParcel reply, int flags); int code, HwParcel request, HwParcel reply, int flags);
public native final void registerService(String serviceName); public native final void registerService(
public static native final IHwBinder getService(String serviceName); String serviceName, int versionMajor, int versionMinor);
public static native final IHwBinder getService(
String serviceName, int versionMajor, int versionMinor);
// Returns address of the "freeFunction". // Returns address of the "freeFunction".
private static native final long native_init(); private static native final long native_init();

View File

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