Use unordered_map in InputEventSender
There are some potential issues with the current usage of KeyedVector (see bug). To work around these issues, use the official std::unordered_map. Bug: 126161446 Test: presubmit Change-Id: I86873a3929ba068c8bb9e60699978d7726a1a444
This commit is contained in:
@@ -23,10 +23,9 @@
|
||||
#include <nativehelper/JNIHelp.h>
|
||||
|
||||
#include <android_runtime/AndroidRuntime.h>
|
||||
#include <utils/Log.h>
|
||||
#include <log/log.h>
|
||||
#include <utils/Looper.h>
|
||||
#include <utils/Vector.h>
|
||||
#include <utils/threads.h>
|
||||
#include <input/InputTransport.h>
|
||||
#include "android_os_MessageQueue.h"
|
||||
#include "android_view_InputChannel.h"
|
||||
|
||||
@@ -21,10 +21,8 @@
|
||||
#include <nativehelper/JNIHelp.h>
|
||||
|
||||
#include <android_runtime/AndroidRuntime.h>
|
||||
#include <utils/Log.h>
|
||||
#include <log/log.h>
|
||||
#include <utils/Looper.h>
|
||||
#include <utils/threads.h>
|
||||
#include <utils/KeyedVector.h>
|
||||
#include <input/InputTransport.h>
|
||||
#include "android_os_MessageQueue.h"
|
||||
#include "android_view_InputChannel.h"
|
||||
@@ -32,6 +30,7 @@
|
||||
#include "android_view_MotionEvent.h"
|
||||
|
||||
#include <nativehelper/ScopedLocalRef.h>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "core_jni_helpers.h"
|
||||
|
||||
@@ -65,7 +64,8 @@ private:
|
||||
jobject mSenderWeakGlobal;
|
||||
InputPublisher mInputPublisher;
|
||||
sp<MessageQueue> mMessageQueue;
|
||||
KeyedVector<uint32_t, uint32_t> mPublishedSeqMap;
|
||||
std::unordered_map<uint32_t, uint32_t> mPublishedSeqMap;
|
||||
|
||||
uint32_t mNextPublishedSeq;
|
||||
|
||||
const std::string getInputChannelName() {
|
||||
@@ -122,7 +122,7 @@ status_t NativeInputEventSender::sendKeyEvent(uint32_t seq, const KeyEvent* even
|
||||
getInputChannelName().c_str(), status);
|
||||
return status;
|
||||
}
|
||||
mPublishedSeqMap.add(publishedSeq, seq);
|
||||
mPublishedSeqMap.emplace(publishedSeq, seq);
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ status_t NativeInputEventSender::sendMotionEvent(uint32_t seq, const MotionEvent
|
||||
return status;
|
||||
}
|
||||
}
|
||||
mPublishedSeqMap.add(publishedSeq, seq);
|
||||
mPublishedSeqMap.emplace(publishedSeq, seq);
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -199,35 +199,37 @@ status_t NativeInputEventSender::receiveFinishedSignals(JNIEnv* env) {
|
||||
return status;
|
||||
}
|
||||
|
||||
ssize_t index = mPublishedSeqMap.indexOfKey(publishedSeq);
|
||||
if (index >= 0) {
|
||||
uint32_t seq = mPublishedSeqMap.valueAt(index);
|
||||
mPublishedSeqMap.removeItemsAt(index);
|
||||
auto it = mPublishedSeqMap.find(publishedSeq);
|
||||
if (it == mPublishedSeqMap.end()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (kDebugDispatchCycle) {
|
||||
ALOGD("channel '%s' ~ Received finished signal, seq=%u, handled=%s, "
|
||||
"pendingEvents=%zu.",
|
||||
getInputChannelName().c_str(), seq, handled ? "true" : "false",
|
||||
mPublishedSeqMap.size());
|
||||
uint32_t seq = it->second;
|
||||
mPublishedSeqMap.erase(it);
|
||||
|
||||
if (kDebugDispatchCycle) {
|
||||
ALOGD("channel '%s' ~ Received finished signal, seq=%u, handled=%s, "
|
||||
"pendingEvents=%zu.",
|
||||
getInputChannelName().c_str(), seq, handled ? "true" : "false",
|
||||
mPublishedSeqMap.size());
|
||||
}
|
||||
|
||||
if (!skipCallbacks) {
|
||||
if (!senderObj.get()) {
|
||||
senderObj.reset(jniGetReferent(env, mSenderWeakGlobal));
|
||||
if (!senderObj.get()) {
|
||||
ALOGW("channel '%s' ~ Sender object was finalized "
|
||||
"without being disposed.", getInputChannelName().c_str());
|
||||
return DEAD_OBJECT;
|
||||
}
|
||||
}
|
||||
|
||||
if (!skipCallbacks) {
|
||||
if (!senderObj.get()) {
|
||||
senderObj.reset(jniGetReferent(env, mSenderWeakGlobal));
|
||||
if (!senderObj.get()) {
|
||||
ALOGW("channel '%s' ~ Sender object was finalized "
|
||||
"without being disposed.", getInputChannelName().c_str());
|
||||
return DEAD_OBJECT;
|
||||
}
|
||||
}
|
||||
|
||||
env->CallVoidMethod(senderObj.get(),
|
||||
gInputEventSenderClassInfo.dispatchInputEventFinished,
|
||||
jint(seq), jboolean(handled));
|
||||
if (env->ExceptionCheck()) {
|
||||
ALOGE("Exception dispatching finished signal.");
|
||||
skipCallbacks = true;
|
||||
}
|
||||
env->CallVoidMethod(senderObj.get(),
|
||||
gInputEventSenderClassInfo.dispatchInputEventFinished,
|
||||
jint(seq), jboolean(handled));
|
||||
if (env->ExceptionCheck()) {
|
||||
ALOGE("Exception dispatching finished signal.");
|
||||
skipCallbacks = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user