Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d2188aaa authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

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
parent 3d6fff4d
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -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"
+32 −30
Original line number Diff line number Diff line
@@ -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,10 +199,13 @@ 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;
        }

        uint32_t seq = it->second;
        mPublishedSeqMap.erase(it);

        if (kDebugDispatchCycle) {
            ALOGD("channel '%s' ~ Received finished signal, seq=%u, handled=%s, "
@@ -231,7 +234,6 @@ status_t NativeInputEventSender::receiveFinishedSignals(JNIEnv* env) {
        }
    }
}
}


static jlong nativeInit(JNIEnv* env, jclass clazz, jobject senderWeak,