Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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 "InputEventSender" |
| 18 | |
| 19 | //#define LOG_NDEBUG 0 |
| 20 | |
Steven Moreland | 2279b25 | 2017-07-19 09:50:45 -0700 | [diff] [blame] | 21 | #include <nativehelper/JNIHelp.h> |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 22 | |
| 23 | #include <android_runtime/AndroidRuntime.h> |
Siarhei Vishniakou | d2188aa | 2019-02-25 16:06:37 -0600 | [diff] [blame] | 24 | #include <log/log.h> |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 25 | #include <utils/Looper.h> |
Jeff Brown | 9d3b1a4 | 2013-07-01 19:07:15 -0700 | [diff] [blame] | 26 | #include <input/InputTransport.h> |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 27 | #include "android_os_MessageQueue.h" |
| 28 | #include "android_view_InputChannel.h" |
| 29 | #include "android_view_KeyEvent.h" |
| 30 | #include "android_view_MotionEvent.h" |
| 31 | |
Steven Moreland | 2279b25 | 2017-07-19 09:50:45 -0700 | [diff] [blame] | 32 | #include <nativehelper/ScopedLocalRef.h> |
Siarhei Vishniakou | d2188aa | 2019-02-25 16:06:37 -0600 | [diff] [blame] | 33 | #include <unordered_map> |
Jeff Brown | a4ca8ea | 2013-04-02 18:01:38 -0700 | [diff] [blame] | 34 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 35 | #include "core_jni_helpers.h" |
| 36 | |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 37 | namespace android { |
| 38 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 39 | // Log debug messages about the dispatch cycle. |
| 40 | static const bool kDebugDispatchCycle = false; |
| 41 | |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 42 | static struct { |
| 43 | jclass clazz; |
| 44 | |
| 45 | jmethodID dispatchInputEventFinished; |
| 46 | } gInputEventSenderClassInfo; |
| 47 | |
| 48 | |
| 49 | class NativeInputEventSender : public LooperCallback { |
| 50 | public: |
| 51 | NativeInputEventSender(JNIEnv* env, |
Jeff Brown | a4ca8ea | 2013-04-02 18:01:38 -0700 | [diff] [blame] | 52 | jobject senderWeak, const sp<InputChannel>& inputChannel, |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 53 | const sp<MessageQueue>& messageQueue); |
| 54 | |
| 55 | status_t initialize(); |
| 56 | void dispose(); |
| 57 | status_t sendKeyEvent(uint32_t seq, const KeyEvent* event); |
| 58 | status_t sendMotionEvent(uint32_t seq, const MotionEvent* event); |
| 59 | |
| 60 | protected: |
| 61 | virtual ~NativeInputEventSender(); |
| 62 | |
| 63 | private: |
Jeff Brown | a4ca8ea | 2013-04-02 18:01:38 -0700 | [diff] [blame] | 64 | jobject mSenderWeakGlobal; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 65 | InputPublisher mInputPublisher; |
| 66 | sp<MessageQueue> mMessageQueue; |
Siarhei Vishniakou | d2188aa | 2019-02-25 16:06:37 -0600 | [diff] [blame] | 67 | std::unordered_map<uint32_t, uint32_t> mPublishedSeqMap; |
| 68 | |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 69 | uint32_t mNextPublishedSeq; |
| 70 | |
Siarhei Vishniakou | d6058f4 | 2018-01-04 13:00:48 -0800 | [diff] [blame] | 71 | const std::string getInputChannelName() { |
| 72 | return mInputPublisher.getChannel()->getName(); |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | virtual int handleEvent(int receiveFd, int events, void* data); |
| 76 | status_t receiveFinishedSignals(JNIEnv* env); |
| 77 | }; |
| 78 | |
| 79 | |
| 80 | NativeInputEventSender::NativeInputEventSender(JNIEnv* env, |
Jeff Brown | a4ca8ea | 2013-04-02 18:01:38 -0700 | [diff] [blame] | 81 | jobject senderWeak, const sp<InputChannel>& inputChannel, |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 82 | const sp<MessageQueue>& messageQueue) : |
Jeff Brown | a4ca8ea | 2013-04-02 18:01:38 -0700 | [diff] [blame] | 83 | mSenderWeakGlobal(env->NewGlobalRef(senderWeak)), |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 84 | mInputPublisher(inputChannel), mMessageQueue(messageQueue), |
Michael Wright | 10f9b09 | 2013-04-01 13:11:34 -0700 | [diff] [blame] | 85 | mNextPublishedSeq(1) { |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 86 | if (kDebugDispatchCycle) { |
Siarhei Vishniakou | d6058f4 | 2018-01-04 13:00:48 -0800 | [diff] [blame] | 87 | ALOGD("channel '%s' ~ Initializing input event sender.", getInputChannelName().c_str()); |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 88 | } |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | NativeInputEventSender::~NativeInputEventSender() { |
| 92 | JNIEnv* env = AndroidRuntime::getJNIEnv(); |
Jeff Brown | a4ca8ea | 2013-04-02 18:01:38 -0700 | [diff] [blame] | 93 | env->DeleteGlobalRef(mSenderWeakGlobal); |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | status_t NativeInputEventSender::initialize() { |
| 97 | int receiveFd = mInputPublisher.getChannel()->getFd(); |
| 98 | mMessageQueue->getLooper()->addFd(receiveFd, 0, ALOOPER_EVENT_INPUT, this, NULL); |
| 99 | return OK; |
| 100 | } |
| 101 | |
| 102 | void NativeInputEventSender::dispose() { |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 103 | if (kDebugDispatchCycle) { |
Siarhei Vishniakou | d6058f4 | 2018-01-04 13:00:48 -0800 | [diff] [blame] | 104 | ALOGD("channel '%s' ~ Disposing input event sender.", getInputChannelName().c_str()); |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 105 | } |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 106 | |
| 107 | mMessageQueue->getLooper()->removeFd(mInputPublisher.getChannel()->getFd()); |
| 108 | } |
| 109 | |
| 110 | status_t NativeInputEventSender::sendKeyEvent(uint32_t seq, const KeyEvent* event) { |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 111 | if (kDebugDispatchCycle) { |
Siarhei Vishniakou | d6058f4 | 2018-01-04 13:00:48 -0800 | [diff] [blame] | 112 | ALOGD("channel '%s' ~ Sending key event, seq=%u.", getInputChannelName().c_str(), seq); |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 113 | } |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 114 | |
| 115 | uint32_t publishedSeq = mNextPublishedSeq++; |
| 116 | status_t status = mInputPublisher.publishKeyEvent(publishedSeq, |
Siarhei Vishniakou | 91fa08f | 2018-06-08 22:49:30 +0100 | [diff] [blame] | 117 | event->getDeviceId(), event->getSource(), event->getDisplayId(), event->getAction(), |
| 118 | event->getFlags(), event->getKeyCode(), event->getScanCode(), event->getMetaState(), |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 119 | event->getRepeatCount(), event->getDownTime(), event->getEventTime()); |
| 120 | if (status) { |
| 121 | ALOGW("Failed to send key event on channel '%s'. status=%d", |
Siarhei Vishniakou | d6058f4 | 2018-01-04 13:00:48 -0800 | [diff] [blame] | 122 | getInputChannelName().c_str(), status); |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 123 | return status; |
| 124 | } |
Siarhei Vishniakou | d2188aa | 2019-02-25 16:06:37 -0600 | [diff] [blame] | 125 | mPublishedSeqMap.emplace(publishedSeq, seq); |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 126 | return OK; |
| 127 | } |
| 128 | |
| 129 | status_t NativeInputEventSender::sendMotionEvent(uint32_t seq, const MotionEvent* event) { |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 130 | if (kDebugDispatchCycle) { |
Siarhei Vishniakou | d6058f4 | 2018-01-04 13:00:48 -0800 | [diff] [blame] | 131 | ALOGD("channel '%s' ~ Sending motion event, seq=%u.", getInputChannelName().c_str(), seq); |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 132 | } |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 133 | |
| 134 | uint32_t publishedSeq; |
| 135 | for (size_t i = 0; i <= event->getHistorySize(); i++) { |
| 136 | publishedSeq = mNextPublishedSeq++; |
| 137 | status_t status = mInputPublisher.publishMotionEvent(publishedSeq, |
Siarhei Vishniakou | 91fa08f | 2018-06-08 22:49:30 +0100 | [diff] [blame] | 138 | event->getDeviceId(), event->getSource(), event->getDisplayId(), |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 139 | event->getAction(), event->getActionButton(), event->getFlags(), |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 140 | event->getEdgeFlags(), event->getMetaState(), event->getButtonState(), |
Siarhei Vishniakou | 0fae870 | 2019-01-14 17:37:31 -0800 | [diff] [blame] | 141 | event->getClassification(), |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 142 | event->getXOffset(), event->getYOffset(), |
| 143 | event->getXPrecision(), event->getYPrecision(), |
| 144 | event->getDownTime(), event->getHistoricalEventTime(i), |
| 145 | event->getPointerCount(), event->getPointerProperties(), |
| 146 | event->getHistoricalRawPointerCoords(0, i)); |
| 147 | if (status) { |
| 148 | ALOGW("Failed to send motion event sample on channel '%s'. status=%d", |
Siarhei Vishniakou | d6058f4 | 2018-01-04 13:00:48 -0800 | [diff] [blame] | 149 | getInputChannelName().c_str(), status); |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 150 | return status; |
| 151 | } |
| 152 | } |
Siarhei Vishniakou | d2188aa | 2019-02-25 16:06:37 -0600 | [diff] [blame] | 153 | mPublishedSeqMap.emplace(publishedSeq, seq); |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 154 | return OK; |
| 155 | } |
| 156 | |
| 157 | int NativeInputEventSender::handleEvent(int receiveFd, int events, void* data) { |
| 158 | if (events & (ALOOPER_EVENT_ERROR | ALOOPER_EVENT_HANGUP)) { |
Jeff Brown | 44e13ef | 2013-03-27 12:34:30 -0700 | [diff] [blame] | 159 | // This error typically occurs when the consumer has closed the input channel |
| 160 | // as part of finishing an IME session, in which case the publisher will |
| 161 | // soon be disposed as well. |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 162 | if (kDebugDispatchCycle) { |
| 163 | ALOGD("channel '%s' ~ Consumer closed input channel or an error occurred. " |
Siarhei Vishniakou | d6058f4 | 2018-01-04 13:00:48 -0800 | [diff] [blame] | 164 | "events=0x%x", getInputChannelName().c_str(), events); |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 165 | } |
| 166 | |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 167 | return 0; // remove the callback |
| 168 | } |
| 169 | |
| 170 | if (!(events & ALOOPER_EVENT_INPUT)) { |
| 171 | ALOGW("channel '%s' ~ Received spurious callback for unhandled poll event. " |
Siarhei Vishniakou | d6058f4 | 2018-01-04 13:00:48 -0800 | [diff] [blame] | 172 | "events=0x%x", getInputChannelName().c_str(), events); |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 173 | return 1; |
| 174 | } |
| 175 | |
| 176 | JNIEnv* env = AndroidRuntime::getJNIEnv(); |
| 177 | status_t status = receiveFinishedSignals(env); |
| 178 | mMessageQueue->raiseAndClearException(env, "handleReceiveCallback"); |
| 179 | return status == OK || status == NO_MEMORY ? 1 : 0; |
| 180 | } |
| 181 | |
| 182 | status_t NativeInputEventSender::receiveFinishedSignals(JNIEnv* env) { |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 183 | if (kDebugDispatchCycle) { |
Siarhei Vishniakou | d6058f4 | 2018-01-04 13:00:48 -0800 | [diff] [blame] | 184 | ALOGD("channel '%s' ~ Receiving finished signals.", getInputChannelName().c_str()); |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 185 | } |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 186 | |
Jeff Brown | a4ca8ea | 2013-04-02 18:01:38 -0700 | [diff] [blame] | 187 | ScopedLocalRef<jobject> senderObj(env, NULL); |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 188 | bool skipCallbacks = false; |
| 189 | for (;;) { |
| 190 | uint32_t publishedSeq; |
| 191 | bool handled; |
| 192 | status_t status = mInputPublisher.receiveFinishedSignal(&publishedSeq, &handled); |
| 193 | if (status) { |
| 194 | if (status == WOULD_BLOCK) { |
| 195 | return OK; |
| 196 | } |
| 197 | ALOGE("channel '%s' ~ Failed to consume finished signals. status=%d", |
Siarhei Vishniakou | d6058f4 | 2018-01-04 13:00:48 -0800 | [diff] [blame] | 198 | getInputChannelName().c_str(), status); |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 199 | return status; |
| 200 | } |
| 201 | |
Siarhei Vishniakou | d2188aa | 2019-02-25 16:06:37 -0600 | [diff] [blame] | 202 | auto it = mPublishedSeqMap.find(publishedSeq); |
| 203 | if (it == mPublishedSeqMap.end()) { |
| 204 | continue; |
| 205 | } |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 206 | |
Siarhei Vishniakou | d2188aa | 2019-02-25 16:06:37 -0600 | [diff] [blame] | 207 | uint32_t seq = it->second; |
| 208 | mPublishedSeqMap.erase(it); |
| 209 | |
| 210 | if (kDebugDispatchCycle) { |
| 211 | ALOGD("channel '%s' ~ Received finished signal, seq=%u, handled=%s, " |
| 212 | "pendingEvents=%zu.", |
| 213 | getInputChannelName().c_str(), seq, handled ? "true" : "false", |
| 214 | mPublishedSeqMap.size()); |
| 215 | } |
| 216 | |
| 217 | if (!skipCallbacks) { |
| 218 | if (!senderObj.get()) { |
| 219 | senderObj.reset(jniGetReferent(env, mSenderWeakGlobal)); |
| 220 | if (!senderObj.get()) { |
| 221 | ALOGW("channel '%s' ~ Sender object was finalized " |
| 222 | "without being disposed.", getInputChannelName().c_str()); |
| 223 | return DEAD_OBJECT; |
| 224 | } |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 225 | } |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 226 | |
Siarhei Vishniakou | d2188aa | 2019-02-25 16:06:37 -0600 | [diff] [blame] | 227 | env->CallVoidMethod(senderObj.get(), |
| 228 | gInputEventSenderClassInfo.dispatchInputEventFinished, |
| 229 | jint(seq), jboolean(handled)); |
| 230 | if (env->ExceptionCheck()) { |
| 231 | ALOGE("Exception dispatching finished signal."); |
| 232 | skipCallbacks = true; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 233 | } |
| 234 | } |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | |
Ashok Bhat | a931d521 | 2014-01-08 14:04:51 +0000 | [diff] [blame] | 239 | static jlong nativeInit(JNIEnv* env, jclass clazz, jobject senderWeak, |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 240 | jobject inputChannelObj, jobject messageQueueObj) { |
| 241 | sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env, |
| 242 | inputChannelObj); |
| 243 | if (inputChannel == NULL) { |
| 244 | jniThrowRuntimeException(env, "InputChannel is not initialized."); |
| 245 | return 0; |
| 246 | } |
| 247 | |
| 248 | sp<MessageQueue> messageQueue = android_os_MessageQueue_getMessageQueue(env, messageQueueObj); |
| 249 | if (messageQueue == NULL) { |
| 250 | jniThrowRuntimeException(env, "MessageQueue is not initialized."); |
| 251 | return 0; |
| 252 | } |
| 253 | |
| 254 | sp<NativeInputEventSender> sender = new NativeInputEventSender(env, |
Jeff Brown | a4ca8ea | 2013-04-02 18:01:38 -0700 | [diff] [blame] | 255 | senderWeak, inputChannel, messageQueue); |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 256 | status_t status = sender->initialize(); |
| 257 | if (status) { |
| 258 | String8 message; |
| 259 | message.appendFormat("Failed to initialize input event sender. status=%d", status); |
| 260 | jniThrowRuntimeException(env, message.string()); |
| 261 | return 0; |
| 262 | } |
| 263 | |
| 264 | sender->incStrong(gInputEventSenderClassInfo.clazz); // retain a reference for the object |
Ashok Bhat | a931d521 | 2014-01-08 14:04:51 +0000 | [diff] [blame] | 265 | return reinterpret_cast<jlong>(sender.get()); |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Ashok Bhat | a931d521 | 2014-01-08 14:04:51 +0000 | [diff] [blame] | 268 | static void nativeDispose(JNIEnv* env, jclass clazz, jlong senderPtr) { |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 269 | sp<NativeInputEventSender> sender = |
| 270 | reinterpret_cast<NativeInputEventSender*>(senderPtr); |
| 271 | sender->dispose(); |
| 272 | sender->decStrong(gInputEventSenderClassInfo.clazz); // drop reference held by the object |
| 273 | } |
| 274 | |
Ashok Bhat | a931d521 | 2014-01-08 14:04:51 +0000 | [diff] [blame] | 275 | static jboolean nativeSendKeyEvent(JNIEnv* env, jclass clazz, jlong senderPtr, |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 276 | jint seq, jobject eventObj) { |
| 277 | sp<NativeInputEventSender> sender = |
| 278 | reinterpret_cast<NativeInputEventSender*>(senderPtr); |
| 279 | KeyEvent event; |
| 280 | android_view_KeyEvent_toNative(env, eventObj, &event); |
| 281 | status_t status = sender->sendKeyEvent(seq, &event); |
| 282 | return !status; |
| 283 | } |
| 284 | |
Ashok Bhat | a931d521 | 2014-01-08 14:04:51 +0000 | [diff] [blame] | 285 | static jboolean nativeSendMotionEvent(JNIEnv* env, jclass clazz, jlong senderPtr, |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 286 | jint seq, jobject eventObj) { |
| 287 | sp<NativeInputEventSender> sender = |
| 288 | reinterpret_cast<NativeInputEventSender*>(senderPtr); |
| 289 | MotionEvent* event = android_view_MotionEvent_getNativePtr(env, eventObj); |
| 290 | status_t status = sender->sendMotionEvent(seq, event); |
| 291 | return !status; |
| 292 | } |
| 293 | |
| 294 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 295 | static const JNINativeMethod gMethods[] = { |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 296 | /* name, signature, funcPtr */ |
| 297 | { "nativeInit", |
Ashok Bhat | a931d521 | 2014-01-08 14:04:51 +0000 | [diff] [blame] | 298 | "(Ljava/lang/ref/WeakReference;Landroid/view/InputChannel;Landroid/os/MessageQueue;)J", |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 299 | (void*)nativeInit }, |
Ashok Bhat | a931d521 | 2014-01-08 14:04:51 +0000 | [diff] [blame] | 300 | { "nativeDispose", "(J)V", |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 301 | (void*)nativeDispose }, |
Ashok Bhat | a931d521 | 2014-01-08 14:04:51 +0000 | [diff] [blame] | 302 | { "nativeSendKeyEvent", "(JILandroid/view/KeyEvent;)Z", |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 303 | (void*)nativeSendKeyEvent }, |
Ashok Bhat | a931d521 | 2014-01-08 14:04:51 +0000 | [diff] [blame] | 304 | { "nativeSendMotionEvent", "(JILandroid/view/MotionEvent;)Z", |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 305 | (void*)nativeSendMotionEvent }, |
| 306 | }; |
| 307 | |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 308 | int register_android_view_InputEventSender(JNIEnv* env) { |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 309 | int res = RegisterMethodsOrDie(env, "android/view/InputEventSender", gMethods, NELEM(gMethods)); |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 310 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 311 | jclass clazz = FindClassOrDie(env, "android/view/InputEventSender"); |
| 312 | gInputEventSenderClassInfo.clazz = MakeGlobalRefOrDie(env, clazz); |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 313 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 314 | gInputEventSenderClassInfo.dispatchInputEventFinished = GetMethodIDOrDie( |
| 315 | env, gInputEventSenderClassInfo.clazz, "dispatchInputEventFinished", "(IZ)V"); |
| 316 | |
| 317 | return res; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | } // namespace android |