diff options
author | Mike Lockwood <lockwood@android.com> | 2009-05-23 10:36:58 -0700 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-05-23 10:36:58 -0700 |
commit | b57d6c9939190f440d3e13adb5fafba6a0cf653d (patch) | |
tree | 83d8e33dfb2a54d19078115e7d76491b09516837 /services/jni | |
parent | a742dc421bd17117ec802b944190a1c731e05a91 (diff) | |
parent | 270e87f71abc2edf446dbec20c725c823e8c7f37 (diff) | |
download | frameworks_base-b57d6c9939190f440d3e13adb5fafba6a0cf653d.zip frameworks_base-b57d6c9939190f440d3e13adb5fafba6a0cf653d.tar.gz frameworks_base-b57d6c9939190f440d3e13adb5fafba6a0cf653d.tar.bz2 |
am 270e87f7: Sensors: Use a native_handle for the data channel instead of a single file descriptor.
Merge commit '270e87f71abc2edf446dbec20c725c823e8c7f37'
* commit '270e87f71abc2edf446dbec20c725c823e8c7f37':
Sensors: Use a native_handle for the data channel instead of a single file descriptor.
Diffstat (limited to 'services/jni')
-rw-r--r-- | services/jni/com_android_server_SensorService.cpp | 77 |
1 files changed, 60 insertions, 17 deletions
diff --git a/services/jni/com_android_server_SensorService.cpp b/services/jni/com_android_server_SensorService.cpp index 695a8a3..7390786 100644 --- a/services/jni/com_android_server_SensorService.cpp +++ b/services/jni/com_android_server_SensorService.cpp @@ -14,7 +14,10 @@ * limitations under the License. */ -#define LOG_TAG "Sensors" +#define LOG_TAG "SensorService" + +#define LOG_NDEBUG 0 +#include "utils/Log.h" #include <hardware/sensors.h> @@ -36,6 +39,14 @@ static struct parcel_file_descriptor_offsets_t jmethodID mConstructor; } gParcelFileDescriptorOffsets; +static struct bundle_descriptor_offsets_t +{ + jclass mClass; + jmethodID mConstructor; + jmethodID mPutIntArray; + jmethodID mPutParcelableArray; +} gBundleOffsets; + /* * The method below are not thread-safe and not intended to be */ @@ -59,21 +70,45 @@ android_init(JNIEnv *env, jclass clazz) static jobject android_open(JNIEnv *env, jclass clazz) { - int fd = sSensorDevice->open_data_source(sSensorDevice); - // new FileDescriptor() - jobject filedescriptor = env->NewObject( - gFileDescriptorOffsets.mClass, - gFileDescriptorOffsets.mConstructor); - - if (filedescriptor != NULL) { - env->SetIntField(filedescriptor, gFileDescriptorOffsets.mDescriptor, fd); - // new ParcelFileDescriptor() - return env->NewObject(gParcelFileDescriptorOffsets.mClass, - gParcelFileDescriptorOffsets.mConstructor, - filedescriptor); + native_handle_t* handle = sSensorDevice->open_data_source(sSensorDevice); + if (!handle) { + return NULL; } - close(fd); - return NULL; + + // new Bundle() + jobject bundle = env->NewObject( + gBundleOffsets.mClass, + gBundleOffsets.mConstructor); + + if (handle->numFds > 0) { + jobjectArray fdArray = env->NewObjectArray(handle->numFds, + gParcelFileDescriptorOffsets.mClass, NULL); + for (int i = 0; i < handle->numFds; i++) { + // new FileDescriptor() + jobject fd = env->NewObject(gFileDescriptorOffsets.mClass, + gFileDescriptorOffsets.mConstructor); + env->SetIntField(fd, gFileDescriptorOffsets.mDescriptor, handle->data[i]); + // new ParcelFileDescriptor() + jobject pfd = env->NewObject(gParcelFileDescriptorOffsets.mClass, + gParcelFileDescriptorOffsets.mConstructor, fd); + env->SetObjectArrayElement(fdArray, i, pfd); + } + // bundle.putParcelableArray("fds", fdArray); + env->CallVoidMethod(bundle, gBundleOffsets.mPutParcelableArray, + env->NewStringUTF("fds"), fdArray); + } + + if (handle->numInts > 0) { + jintArray intArray = env->NewIntArray(handle->numInts); + env->SetIntArrayRegion(intArray, 0, handle->numInts, &handle->data[handle->numInts]); + // bundle.putIntArray("ints", intArray); + env->CallVoidMethod(bundle, gBundleOffsets.mPutIntArray, + env->NewStringUTF("ints"), intArray); + } + + // delete the file handle, but don't close any file descriptors + native_handle_delete(handle); + return bundle; } static jboolean @@ -99,7 +134,7 @@ android_data_wake(JNIEnv *env, jclass clazz) static JNINativeMethod gMethods[] = { {"_sensors_control_init", "()I", (void*) android_init }, - {"_sensors_control_open", "()Landroid/os/ParcelFileDescriptor;", (void*) android_open }, + {"_sensors_control_open", "()Landroid/os/Bundle;", (void*) android_open }, {"_sensors_control_activate", "(IZ)Z", (void*) android_activate }, {"_sensors_control_wake", "()I", (void*) android_data_wake }, {"_sensors_control_set_delay","(I)I", (void*) android_set_delay }, @@ -116,7 +151,15 @@ int register_android_server_SensorService(JNIEnv *env) clazz = env->FindClass("android/os/ParcelFileDescriptor"); gParcelFileDescriptorOffsets.mClass = (jclass) env->NewGlobalRef(clazz); - gParcelFileDescriptorOffsets.mConstructor = env->GetMethodID(clazz, "<init>", "(Ljava/io/FileDescriptor;)V"); + gParcelFileDescriptorOffsets.mConstructor = env->GetMethodID(clazz, "<init>", + "(Ljava/io/FileDescriptor;)V"); + + clazz = env->FindClass("android/os/Bundle"); + gBundleOffsets.mClass = (jclass) env->NewGlobalRef(clazz); + gBundleOffsets.mConstructor = env->GetMethodID(clazz, "<init>", "()V"); + gBundleOffsets.mPutIntArray = env->GetMethodID(clazz, "putIntArray", "(Ljava/lang/String;[I)V"); + gBundleOffsets.mPutParcelableArray = env->GetMethodID(clazz, "putParcelableArray", + "(Ljava/lang/String;[Landroid/os/Parcelable;)V"); return jniRegisterNativeMethods(env, "com/android/server/SensorService", gMethods, NELEM(gMethods)); |