Skip to content

Commit

Permalink
Merge "Adds support for specifying the version of a service to regist…
Browse files Browse the repository at this point in the history
…er/lookup."
  • Loading branch information
theandi666 authored and Gerrit Code Review committed Oct 26, 2016
2 parents 4d1c292 + 35eb799 commit c3d8550
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
7 changes: 5 additions & 2 deletions core/java/android/os/HwBinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ public final native void transact(
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();
Expand Down
38 changes: 32 additions & 6 deletions core/jni/android_os_HwBinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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(
Expand Down Expand Up @@ -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 },
};

Expand Down

0 comments on commit c3d8550

Please sign in to comment.