blob: e64ec4ee4c8c1d45ab5e8dd3005cb13b9d4d8b5d [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 {
29 jclass clazz;
30
31 jfieldID inputApplicationHandle;
32 jfieldID name;
33 jfieldID dispatchingTimeoutNanos;
34} gInputApplicationClassInfo;
35
36
37// --- Global functions ---
38
39void android_server_InputApplication_toNative(
40 JNIEnv* env, jobject inputApplicationObj, InputApplication* outInputApplication) {
41 jobject inputApplicationHandleObj = env->GetObjectField(inputApplicationObj,
42 gInputApplicationClassInfo.inputApplicationHandle);
43 if (inputApplicationHandleObj) {
44 outInputApplication->inputApplicationHandle =
45 android_server_InputApplicationHandle_getHandle(env, inputApplicationHandleObj);
46 env->DeleteLocalRef(inputApplicationHandleObj);
47 } else {
48 outInputApplication->inputApplicationHandle = NULL;
49 }
50
51 jstring nameObj = jstring(env->GetObjectField(inputApplicationObj,
52 gInputApplicationClassInfo.name));
53 if (nameObj) {
54 const char* nameStr = env->GetStringUTFChars(nameObj, NULL);
55 outInputApplication->name.setTo(nameStr);
56 env->ReleaseStringUTFChars(nameObj, nameStr);
57 env->DeleteLocalRef(nameObj);
58 } else {
59 LOGE("InputApplication.name should not be null.");
60 outInputApplication->name.setTo("unknown");
61 }
62
63 outInputApplication->dispatchingTimeout = env->GetLongField(inputApplicationObj,
64 gInputApplicationClassInfo.dispatchingTimeoutNanos);
65}
66
67
68// --- JNI ---
69
70#define FIND_CLASS(var, className) \
71 var = env->FindClass(className); \
72 LOG_FATAL_IF(! var, "Unable to find class " className); \
73 var = jclass(env->NewGlobalRef(var));
74
75#define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \
76 var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \
77 LOG_FATAL_IF(! var, "Unable to find field " fieldName);
78
79int register_android_server_InputApplication(JNIEnv* env) {
Dianne Hackborna924dc0d2011-02-17 14:22:17 -080080 FIND_CLASS(gInputApplicationClassInfo.clazz, "com/android/server/wm/InputApplication");
Jeff Brown928e0542011-01-10 11:17:36 -080081
82 GET_FIELD_ID(gInputApplicationClassInfo.inputApplicationHandle,
83 gInputApplicationClassInfo.clazz,
Dianne Hackborna924dc0d2011-02-17 14:22:17 -080084 "inputApplicationHandle", "Lcom/android/server/wm/InputApplicationHandle;");
Jeff Brown928e0542011-01-10 11:17:36 -080085
86 GET_FIELD_ID(gInputApplicationClassInfo.name, gInputApplicationClassInfo.clazz,
87 "name", "Ljava/lang/String;");
88
89 GET_FIELD_ID(gInputApplicationClassInfo.dispatchingTimeoutNanos,
90 gInputApplicationClassInfo.clazz,
91 "dispatchingTimeoutNanos", "J");
92 return 0;
93}
94
95} /* namespace android */