Merge "Track all published motion events in InputEventSender" am: d964f195dd

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2469530

Change-Id: Ieb04a1f056e5496dd34c565c2cbd1ad8e2a7335d
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Tom Cherry
2023-03-06 18:18:26 +00:00
committed by Automerger Merge Worker

View File

@@ -20,20 +20,21 @@
#include <android_runtime/AndroidRuntime.h> #include <android_runtime/AndroidRuntime.h>
#include <input/InputTransport.h> #include <input/InputTransport.h>
#include <inttypes.h>
#include <log/log.h> #include <log/log.h>
#include <nativehelper/JNIHelp.h> #include <nativehelper/JNIHelp.h>
#include <nativehelper/ScopedLocalRef.h> #include <nativehelper/ScopedLocalRef.h>
#include <utils/Looper.h> #include <utils/Looper.h>
#include <optional>
#include <unordered_map>
#include "android_os_MessageQueue.h" #include "android_os_MessageQueue.h"
#include "android_view_InputChannel.h" #include "android_view_InputChannel.h"
#include "android_view_KeyEvent.h" #include "android_view_KeyEvent.h"
#include "android_view_MotionEvent.h" #include "android_view_MotionEvent.h"
#include "core_jni_helpers.h" #include "core_jni_helpers.h"
#include <inttypes.h>
#include <unordered_map>
using android::base::Result; using android::base::Result;
namespace android { namespace android {
@@ -67,7 +68,7 @@ private:
jobject mSenderWeakGlobal; jobject mSenderWeakGlobal;
InputPublisher mInputPublisher; InputPublisher mInputPublisher;
sp<MessageQueue> mMessageQueue; sp<MessageQueue> mMessageQueue;
std::unordered_map<uint32_t, uint32_t> mPublishedSeqMap; std::unordered_map<uint32_t, std::optional<uint32_t>> mPublishedSeqMap;
uint32_t mNextPublishedSeq; uint32_t mNextPublishedSeq;
@@ -165,8 +166,14 @@ status_t NativeInputEventSender::sendMotionEvent(uint32_t seq, const MotionEvent
getInputChannelName().c_str(), status); getInputChannelName().c_str(), status);
return status; return status;
} }
// mPublishedSeqMap tracks all sequences published from this sender. Only the last
// sequence number is used to signal this motion event is finished.
if (i == event->getHistorySize()) {
mPublishedSeqMap.emplace(publishedSeq, seq);
} else {
mPublishedSeqMap.emplace(publishedSeq, std::nullopt);
}
} }
mPublishedSeqMap.emplace(publishedSeq, seq);
return OK; return OK;
} }
@@ -277,8 +284,16 @@ bool NativeInputEventSender::notifyConsumerResponse(
// does something wrong and sends bad data. Just ignore and process other events. // does something wrong and sends bad data. Just ignore and process other events.
return true; return true;
} }
const uint32_t seq = it->second;
const std::optional<uint32_t> seqOptional = it->second;
mPublishedSeqMap.erase(it); mPublishedSeqMap.erase(it);
// If this optional does not have a value, it means we are processing an event that had history
// and was split. There are more events coming, so we can't call 'dispatchInputEventFinished'
// yet. The final split event will have a valid sequence number.
if (!seqOptional.has_value()) {
return true;
}
const uint32_t seq = seqOptional.value();
if (kDebugDispatchCycle) { if (kDebugDispatchCycle) {
ALOGD("channel '%s' ~ Received finished signal, seq=%u, handled=%s, pendingEvents=%zu.", ALOGD("channel '%s' ~ Received finished signal, seq=%u, handled=%s, pendingEvents=%zu.",