Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #define LOG_TAG "InputApplication" |
| 18 | |
| 19 | #include "JNIHelp.h" |
| 20 | #include "jni.h" |
| 21 | #include <android_runtime/AndroidRuntime.h> |
| 22 | |
| 23 | #include "com_android_server_InputApplication.h" |
| 24 | #include "com_android_server_InputApplicationHandle.h" |
| 25 | |
| 26 | namespace android { |
| 27 | |
| 28 | static struct { |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 29 | jfieldID inputApplicationHandle; |
| 30 | jfieldID name; |
| 31 | jfieldID dispatchingTimeoutNanos; |
| 32 | } gInputApplicationClassInfo; |
| 33 | |
| 34 | |
| 35 | // --- Global functions --- |
| 36 | |
| 37 | void android_server_InputApplication_toNative( |
| 38 | JNIEnv* env, jobject inputApplicationObj, InputApplication* outInputApplication) { |
| 39 | jobject inputApplicationHandleObj = env->GetObjectField(inputApplicationObj, |
| 40 | gInputApplicationClassInfo.inputApplicationHandle); |
| 41 | if (inputApplicationHandleObj) { |
| 42 | outInputApplication->inputApplicationHandle = |
| 43 | android_server_InputApplicationHandle_getHandle(env, inputApplicationHandleObj); |
| 44 | env->DeleteLocalRef(inputApplicationHandleObj); |
| 45 | } else { |
| 46 | outInputApplication->inputApplicationHandle = NULL; |
| 47 | } |
| 48 | |
| 49 | jstring nameObj = jstring(env->GetObjectField(inputApplicationObj, |
| 50 | gInputApplicationClassInfo.name)); |
| 51 | if (nameObj) { |
| 52 | const char* nameStr = env->GetStringUTFChars(nameObj, NULL); |
| 53 | outInputApplication->name.setTo(nameStr); |
| 54 | env->ReleaseStringUTFChars(nameObj, nameStr); |
| 55 | env->DeleteLocalRef(nameObj); |
| 56 | } else { |
| 57 | LOGE("InputApplication.name should not be null."); |
| 58 | outInputApplication->name.setTo("unknown"); |
| 59 | } |
| 60 | |
| 61 | outInputApplication->dispatchingTimeout = env->GetLongField(inputApplicationObj, |
| 62 | gInputApplicationClassInfo.dispatchingTimeoutNanos); |
| 63 | } |
| 64 | |
| 65 | |
| 66 | // --- JNI --- |
| 67 | |
| 68 | #define FIND_CLASS(var, className) \ |
| 69 | var = env->FindClass(className); \ |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 70 | LOG_FATAL_IF(! var, "Unable to find class " className); |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 71 | |
| 72 | #define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \ |
| 73 | var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \ |
| 74 | LOG_FATAL_IF(! var, "Unable to find field " fieldName); |
| 75 | |
| 76 | int register_android_server_InputApplication(JNIEnv* env) { |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 77 | jclass clazz; |
| 78 | FIND_CLASS(clazz, "com/android/server/wm/InputApplication"); |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 79 | |
| 80 | GET_FIELD_ID(gInputApplicationClassInfo.inputApplicationHandle, |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 81 | clazz, |
Dianne Hackborn | a924dc0d | 2011-02-17 14:22:17 -0800 | [diff] [blame] | 82 | "inputApplicationHandle", "Lcom/android/server/wm/InputApplicationHandle;"); |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 83 | |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 84 | GET_FIELD_ID(gInputApplicationClassInfo.name, clazz, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 85 | "name", "Ljava/lang/String;"); |
| 86 | |
| 87 | GET_FIELD_ID(gInputApplicationClassInfo.dispatchingTimeoutNanos, |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 88 | clazz, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 89 | "dispatchingTimeoutNanos", "J"); |
| 90 | return 0; |
| 91 | } |
| 92 | |
| 93 | } /* namespace android */ |