Merge "Adds support for specifying the version of a service to register/lookup."
diff --git a/core/java/android/os/HwBinder.java b/core/java/android/os/HwBinder.java
index 5ff79f7..0e7da63 100644
--- a/core/java/android/os/HwBinder.java
+++ b/core/java/android/os/HwBinder.java
@@ -38,8 +38,11 @@
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();
diff --git a/core/jni/android_os_HwBinder.cpp b/core/jni/android_os_HwBinder.cpp
index 13e3f0d..816d5df 100644
--- a/core/jni/android_os_HwBinder.cpp
+++ b/core/jni/android_os_HwBinder.cpp
@@ -196,19 +196,32 @@
}
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 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 @@
"(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 },
};