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 "InputWindow" |
| 18 | |
| 19 | #include "JNIHelp.h" |
| 20 | #include "jni.h" |
| 21 | #include <android_runtime/AndroidRuntime.h> |
| 22 | |
| 23 | #include <android_view_InputChannel.h> |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 24 | #include <android/graphics/Region.h> |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 25 | #include "com_android_server_InputWindow.h" |
| 26 | #include "com_android_server_InputWindowHandle.h" |
| 27 | |
| 28 | namespace android { |
| 29 | |
| 30 | static struct { |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 31 | 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 Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 41 | jfieldID scaleFactor; |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 42 | jfieldID touchableRegion; |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 43 | 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 | |
| 56 | void 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 Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 104 | outInputWindow->scaleFactor = env->GetFloatField(inputWindowObj, |
| 105 | gInputWindowClassInfo.scaleFactor); |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 106 | |
| 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 Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 117 | 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 Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 140 | LOG_FATAL_IF(! var, "Unable to find class " className); |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 141 | |
| 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 | |
| 146 | int register_android_server_InputWindow(JNIEnv* env) { |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 147 | jclass clazz; |
| 148 | FIND_CLASS(clazz, "com/android/server/wm/InputWindow"); |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 149 | |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 150 | GET_FIELD_ID(gInputWindowClassInfo.inputWindowHandle, clazz, |
Dianne Hackborn | a924dc0d | 2011-02-17 14:22:17 -0800 | [diff] [blame] | 151 | "inputWindowHandle", "Lcom/android/server/wm/InputWindowHandle;"); |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 152 | |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 153 | GET_FIELD_ID(gInputWindowClassInfo.inputChannel, clazz, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 154 | "inputChannel", "Landroid/view/InputChannel;"); |
| 155 | |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 156 | GET_FIELD_ID(gInputWindowClassInfo.name, clazz, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 157 | "name", "Ljava/lang/String;"); |
| 158 | |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 159 | GET_FIELD_ID(gInputWindowClassInfo.layoutParamsFlags, clazz, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 160 | "layoutParamsFlags", "I"); |
| 161 | |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 162 | GET_FIELD_ID(gInputWindowClassInfo.layoutParamsType, clazz, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 163 | "layoutParamsType", "I"); |
| 164 | |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 165 | GET_FIELD_ID(gInputWindowClassInfo.dispatchingTimeoutNanos, clazz, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 166 | "dispatchingTimeoutNanos", "J"); |
| 167 | |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 168 | GET_FIELD_ID(gInputWindowClassInfo.frameLeft, clazz, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 169 | "frameLeft", "I"); |
| 170 | |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 171 | GET_FIELD_ID(gInputWindowClassInfo.frameTop, clazz, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 172 | "frameTop", "I"); |
| 173 | |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 174 | GET_FIELD_ID(gInputWindowClassInfo.frameRight, clazz, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 175 | "frameRight", "I"); |
| 176 | |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 177 | GET_FIELD_ID(gInputWindowClassInfo.frameBottom, clazz, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 178 | "frameBottom", "I"); |
| 179 | |
Dianne Hackborn | aa9d84c | 2011-05-09 19:00:59 -0700 | [diff] [blame] | 180 | GET_FIELD_ID(gInputWindowClassInfo.scaleFactor, clazz, |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 181 | "scaleFactor", "F"); |
| 182 | |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 183 | GET_FIELD_ID(gInputWindowClassInfo.touchableRegion, clazz, |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 184 | "touchableRegion", "Landroid/graphics/Region;"); |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 185 | |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 186 | GET_FIELD_ID(gInputWindowClassInfo.visible, clazz, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 187 | "visible", "Z"); |
| 188 | |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 189 | GET_FIELD_ID(gInputWindowClassInfo.canReceiveKeys, clazz, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 190 | "canReceiveKeys", "Z"); |
| 191 | |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 192 | GET_FIELD_ID(gInputWindowClassInfo.hasFocus, clazz, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 193 | "hasFocus", "Z"); |
| 194 | |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 195 | GET_FIELD_ID(gInputWindowClassInfo.hasWallpaper, clazz, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 196 | "hasWallpaper", "Z"); |
| 197 | |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 198 | GET_FIELD_ID(gInputWindowClassInfo.paused, clazz, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 199 | "paused", "Z"); |
| 200 | |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 201 | GET_FIELD_ID(gInputWindowClassInfo.layer, clazz, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 202 | "layer", "I"); |
| 203 | |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 204 | GET_FIELD_ID(gInputWindowClassInfo.ownerPid, clazz, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 205 | "ownerPid", "I"); |
| 206 | |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 207 | GET_FIELD_ID(gInputWindowClassInfo.ownerUid, clazz, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 208 | "ownerUid", "I"); |
| 209 | return 0; |
| 210 | } |
| 211 | |
| 212 | } /* namespace android */ |