blob: 012ce21d4c28ed14876d45b8388d308a5b821b87 [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 "InputWindow"
18
19#include "JNIHelp.h"
20#include "jni.h"
21#include <android_runtime/AndroidRuntime.h>
22
23#include <android_view_InputChannel.h>
Jeff Brownfbf09772011-01-16 14:06:57 -080024#include <android/graphics/Region.h>
Jeff Brown928e0542011-01-10 11:17:36 -080025#include "com_android_server_InputWindow.h"
26#include "com_android_server_InputWindowHandle.h"
27
28namespace android {
29
30static struct {
Jeff Brown928e0542011-01-10 11:17:36 -080031 jfieldID inputWindowHandle;
32 jfieldID inputChannel;
33 jfieldID name;
34 jfieldID layoutParamsFlags;
35 jfieldID layoutParamsType;
36 jfieldID dispatchingTimeoutNanos;
37 jfieldID frameLeft;
38 jfieldID frameTop;
39 jfieldID frameRight;
40 jfieldID frameBottom;
Dianne Hackborne2515ee2011-04-27 18:52:56 -040041 jfieldID scaleFactor;
Jeff Brownfbf09772011-01-16 14:06:57 -080042 jfieldID touchableRegion;
Jeff Brown928e0542011-01-10 11:17:36 -080043 jfieldID visible;
44 jfieldID canReceiveKeys;
45 jfieldID hasFocus;
46 jfieldID hasWallpaper;
47 jfieldID paused;
48 jfieldID layer;
49 jfieldID ownerPid;
50 jfieldID ownerUid;
51} gInputWindowClassInfo;
52
53
54// --- Global functions ---
55
56void android_server_InputWindow_toNative(
57 JNIEnv* env, jobject inputWindowObj, InputWindow* outInputWindow) {
58 jobject inputWindowHandleObj = env->GetObjectField(inputWindowObj,
59 gInputWindowClassInfo.inputWindowHandle);
60 if (inputWindowHandleObj) {
61 outInputWindow->inputWindowHandle =
62 android_server_InputWindowHandle_getHandle(env, inputWindowHandleObj);
63 env->DeleteLocalRef(inputWindowHandleObj);
64 } else {
65 outInputWindow->inputWindowHandle = NULL;
66 }
67
68 jobject inputChannelObj = env->GetObjectField(inputWindowObj,
69 gInputWindowClassInfo.inputChannel);
70 if (inputChannelObj) {
71 outInputWindow->inputChannel =
72 android_view_InputChannel_getInputChannel(env, inputChannelObj);
73 env->DeleteLocalRef(inputChannelObj);
74 } else {
75 outInputWindow->inputChannel = NULL;
76 }
77
78 jstring nameObj = jstring(env->GetObjectField(inputWindowObj,
79 gInputWindowClassInfo.name));
80 if (nameObj) {
81 const char* nameStr = env->GetStringUTFChars(nameObj, NULL);
82 outInputWindow->name.setTo(nameStr);
83 env->ReleaseStringUTFChars(nameObj, nameStr);
84 env->DeleteLocalRef(nameObj);
85 } else {
86 LOGE("InputWindow.name should not be null.");
87 outInputWindow->name.setTo("unknown");
88 }
89
90 outInputWindow->layoutParamsFlags = env->GetIntField(inputWindowObj,
91 gInputWindowClassInfo.layoutParamsFlags);
92 outInputWindow->layoutParamsType = env->GetIntField(inputWindowObj,
93 gInputWindowClassInfo.layoutParamsType);
94 outInputWindow->dispatchingTimeout = env->GetLongField(inputWindowObj,
95 gInputWindowClassInfo.dispatchingTimeoutNanos);
96 outInputWindow->frameLeft = env->GetIntField(inputWindowObj,
97 gInputWindowClassInfo.frameLeft);
98 outInputWindow->frameTop = env->GetIntField(inputWindowObj,
99 gInputWindowClassInfo.frameTop);
100 outInputWindow->frameRight = env->GetIntField(inputWindowObj,
101 gInputWindowClassInfo.frameRight);
102 outInputWindow->frameBottom = env->GetIntField(inputWindowObj,
103 gInputWindowClassInfo.frameBottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400104 outInputWindow->scaleFactor = env->GetFloatField(inputWindowObj,
105 gInputWindowClassInfo.scaleFactor);
Jeff Brownfbf09772011-01-16 14:06:57 -0800106
107 jobject regionObj = env->GetObjectField(inputWindowObj,
108 gInputWindowClassInfo.touchableRegion);
109 if (regionObj) {
110 SkRegion* region = android_graphics_Region_getSkRegion(env, regionObj);
111 outInputWindow->touchableRegion.set(*region);
112 env->DeleteLocalRef(regionObj);
113 } else {
114 outInputWindow->touchableRegion.setEmpty();
115 }
116
Jeff Brown928e0542011-01-10 11:17:36 -0800117 outInputWindow->visible = env->GetBooleanField(inputWindowObj,
118 gInputWindowClassInfo.visible);
119 outInputWindow->canReceiveKeys = env->GetBooleanField(inputWindowObj,
120 gInputWindowClassInfo.canReceiveKeys);
121 outInputWindow->hasFocus = env->GetBooleanField(inputWindowObj,
122 gInputWindowClassInfo.hasFocus);
123 outInputWindow->hasWallpaper = env->GetBooleanField(inputWindowObj,
124 gInputWindowClassInfo.hasWallpaper);
125 outInputWindow->paused = env->GetBooleanField(inputWindowObj,
126 gInputWindowClassInfo.paused);
127 outInputWindow->layer = env->GetIntField(inputWindowObj,
128 gInputWindowClassInfo.layer);
129 outInputWindow->ownerPid = env->GetIntField(inputWindowObj,
130 gInputWindowClassInfo.ownerPid);
131 outInputWindow->ownerUid = env->GetIntField(inputWindowObj,
132 gInputWindowClassInfo.ownerUid);
133}
134
135
136// --- JNI ---
137
138#define FIND_CLASS(var, className) \
139 var = env->FindClass(className); \
Carl Shapiro17cc33a2011-03-05 20:53:16 -0800140 LOG_FATAL_IF(! var, "Unable to find class " className);
Jeff Brown928e0542011-01-10 11:17:36 -0800141
142#define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \
143 var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \
144 LOG_FATAL_IF(! var, "Unable to find field " fieldName);
145
146int register_android_server_InputWindow(JNIEnv* env) {
Carl Shapiro17cc33a2011-03-05 20:53:16 -0800147 jclass clazz;
148 FIND_CLASS(clazz, "com/android/server/wm/InputWindow");
Jeff Brown928e0542011-01-10 11:17:36 -0800149
Carl Shapiro17cc33a2011-03-05 20:53:16 -0800150 GET_FIELD_ID(gInputWindowClassInfo.inputWindowHandle, clazz,
Dianne Hackborna924dc0d2011-02-17 14:22:17 -0800151 "inputWindowHandle", "Lcom/android/server/wm/InputWindowHandle;");
Jeff Brown928e0542011-01-10 11:17:36 -0800152
Carl Shapiro17cc33a2011-03-05 20:53:16 -0800153 GET_FIELD_ID(gInputWindowClassInfo.inputChannel, clazz,
Jeff Brown928e0542011-01-10 11:17:36 -0800154 "inputChannel", "Landroid/view/InputChannel;");
155
Carl Shapiro17cc33a2011-03-05 20:53:16 -0800156 GET_FIELD_ID(gInputWindowClassInfo.name, clazz,
Jeff Brown928e0542011-01-10 11:17:36 -0800157 "name", "Ljava/lang/String;");
158
Carl Shapiro17cc33a2011-03-05 20:53:16 -0800159 GET_FIELD_ID(gInputWindowClassInfo.layoutParamsFlags, clazz,
Jeff Brown928e0542011-01-10 11:17:36 -0800160 "layoutParamsFlags", "I");
161
Carl Shapiro17cc33a2011-03-05 20:53:16 -0800162 GET_FIELD_ID(gInputWindowClassInfo.layoutParamsType, clazz,
Jeff Brown928e0542011-01-10 11:17:36 -0800163 "layoutParamsType", "I");
164
Carl Shapiro17cc33a2011-03-05 20:53:16 -0800165 GET_FIELD_ID(gInputWindowClassInfo.dispatchingTimeoutNanos, clazz,
Jeff Brown928e0542011-01-10 11:17:36 -0800166 "dispatchingTimeoutNanos", "J");
167
Carl Shapiro17cc33a2011-03-05 20:53:16 -0800168 GET_FIELD_ID(gInputWindowClassInfo.frameLeft, clazz,
Jeff Brown928e0542011-01-10 11:17:36 -0800169 "frameLeft", "I");
170
Carl Shapiro17cc33a2011-03-05 20:53:16 -0800171 GET_FIELD_ID(gInputWindowClassInfo.frameTop, clazz,
Jeff Brown928e0542011-01-10 11:17:36 -0800172 "frameTop", "I");
173
Carl Shapiro17cc33a2011-03-05 20:53:16 -0800174 GET_FIELD_ID(gInputWindowClassInfo.frameRight, clazz,
Jeff Brown928e0542011-01-10 11:17:36 -0800175 "frameRight", "I");
176
Carl Shapiro17cc33a2011-03-05 20:53:16 -0800177 GET_FIELD_ID(gInputWindowClassInfo.frameBottom, clazz,
Jeff Brown928e0542011-01-10 11:17:36 -0800178 "frameBottom", "I");
179
Dianne Hackbornaa9d84c2011-05-09 19:00:59 -0700180 GET_FIELD_ID(gInputWindowClassInfo.scaleFactor, clazz,
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400181 "scaleFactor", "F");
182
Carl Shapiro17cc33a2011-03-05 20:53:16 -0800183 GET_FIELD_ID(gInputWindowClassInfo.touchableRegion, clazz,
Jeff Brownfbf09772011-01-16 14:06:57 -0800184 "touchableRegion", "Landroid/graphics/Region;");
Jeff Brown928e0542011-01-10 11:17:36 -0800185
Carl Shapiro17cc33a2011-03-05 20:53:16 -0800186 GET_FIELD_ID(gInputWindowClassInfo.visible, clazz,
Jeff Brown928e0542011-01-10 11:17:36 -0800187 "visible", "Z");
188
Carl Shapiro17cc33a2011-03-05 20:53:16 -0800189 GET_FIELD_ID(gInputWindowClassInfo.canReceiveKeys, clazz,
Jeff Brown928e0542011-01-10 11:17:36 -0800190 "canReceiveKeys", "Z");
191
Carl Shapiro17cc33a2011-03-05 20:53:16 -0800192 GET_FIELD_ID(gInputWindowClassInfo.hasFocus, clazz,
Jeff Brown928e0542011-01-10 11:17:36 -0800193 "hasFocus", "Z");
194
Carl Shapiro17cc33a2011-03-05 20:53:16 -0800195 GET_FIELD_ID(gInputWindowClassInfo.hasWallpaper, clazz,
Jeff Brown928e0542011-01-10 11:17:36 -0800196 "hasWallpaper", "Z");
197
Carl Shapiro17cc33a2011-03-05 20:53:16 -0800198 GET_FIELD_ID(gInputWindowClassInfo.paused, clazz,
Jeff Brown928e0542011-01-10 11:17:36 -0800199 "paused", "Z");
200
Carl Shapiro17cc33a2011-03-05 20:53:16 -0800201 GET_FIELD_ID(gInputWindowClassInfo.layer, clazz,
Jeff Brown928e0542011-01-10 11:17:36 -0800202 "layer", "I");
203
Carl Shapiro17cc33a2011-03-05 20:53:16 -0800204 GET_FIELD_ID(gInputWindowClassInfo.ownerPid, clazz,
Jeff Brown928e0542011-01-10 11:17:36 -0800205 "ownerPid", "I");
206
Carl Shapiro17cc33a2011-03-05 20:53:16 -0800207 GET_FIELD_ID(gInputWindowClassInfo.ownerUid, clazz,
Jeff Brown928e0542011-01-10 11:17:36 -0800208 "ownerUid", "I");
209 return 0;
210}
211
212} /* namespace android */