blob: 1f80242ceacccba1e5e5e88ee7d0848f3ed8228d [file] [log] [blame]
Jeff Brown928e0542011-01-10 11:17:36 -08001/*
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
26namespace android {
27
28static struct {
Jeff Brown928e0542011-01-10 11:17:36 -080029 jfieldID inputApplicationHandle;
30 jfieldID name;
31 jfieldID dispatchingTimeoutNanos;
32} gInputApplicationClassInfo;
33
34
35// --- Global functions ---
36
37void 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 Shapiro17cc33a2011-03-05 20:53:16 -080070 LOG_FATAL_IF(! var, "Unable to find class " className);
Jeff Brown928e0542011-01-10 11:17:36 -080071
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
76int register_android_server_InputApplication(JNIEnv* env) {
Carl Shapiro17cc33a2011-03-05 20:53:16 -080077 jclass clazz;
78 FIND_CLASS(clazz, "com/android/server/wm/InputApplication");
Jeff Brown928e0542011-01-10 11:17:36 -080079
80 GET_FIELD_ID(gInputApplicationClassInfo.inputApplicationHandle,
Carl Shapiro17cc33a2011-03-05 20:53:16 -080081 clazz,
Dianne Hackborna924dc0d2011-02-17 14:22:17 -080082 "inputApplicationHandle", "Lcom/android/server/wm/InputApplicationHandle;");
Jeff Brown928e0542011-01-10 11:17:36 -080083
Carl Shapiro17cc33a2011-03-05 20:53:16 -080084 GET_FIELD_ID(gInputApplicationClassInfo.name, clazz,
Jeff Brown928e0542011-01-10 11:17:36 -080085 "name", "Ljava/lang/String;");
86
87 GET_FIELD_ID(gInputApplicationClassInfo.dispatchingTimeoutNanos,
Carl Shapiro17cc33a2011-03-05 20:53:16 -080088 clazz,
Jeff Brown928e0542011-01-10 11:17:36 -080089 "dispatchingTimeoutNanos", "J");
90 return 0;
91}
92
93} /* namespace android */