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

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

Get the token from native receiver instead of java channel

This will help us in future CL completely transfer the ownership of
InputChannel to the InputEventReceiver.

Bug: 323450804
Test: none
Flag: EXEMPT refactor
Change-Id: Id5545dc20d7188e625e1a2193f9ec4ad3009d9df
parent 14dd4f8a
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ public abstract class InputEventReceiver {
            long gpuCompletedTime, long presentTime);
    private static native boolean nativeConsumeBatchedInputEvents(long receiverPtr,
            long frameTimeNanos);
    private static native IBinder nativeGetToken(long receiverPtr);
    private static native String nativeDump(long receiverPtr, String prefix);

    /**
@@ -268,10 +269,10 @@ public abstract class InputEventReceiver {
     * @return Returns a token to identify the input channel.
     */
    public IBinder getToken() {
        if (mInputChannel == null) {
        if (mReceiverPtr == 0) {
            return null;
        }
        return mInputChannel.getToken();
        return nativeGetToken(mReceiverPtr);
    }

    private String getShortDescription(InputEvent event) {
+17 −4
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@
#include <vector>

#include "android_os_MessageQueue.h"
#include "android_util_Binder.h"
#include "android_view_InputChannel.h"
#include "android_view_KeyEvent.h"
#include "android_view_MotionEvent.h"
@@ -93,11 +94,12 @@ public:
    status_t initialize();
    void dispose();
    status_t finishInputEvent(uint32_t seq, bool handled);
    bool probablyHasInput();
    bool probablyHasInput() const;
    status_t reportTimeline(int32_t inputEventId, nsecs_t gpuCompletedTime, nsecs_t presentTime);
    status_t consumeEvents(JNIEnv* env, bool consumeBatches, nsecs_t frameTime,
            bool* outConsumedBatch);
    std::string dump(const char* prefix);
    sp<IBinder> getInputChannelToken() const;
    std::string dump(const char* prefix) const;

protected:
    ~NativeInputEventReceiver() override;
@@ -182,7 +184,7 @@ status_t NativeInputEventReceiver::finishInputEvent(uint32_t seq, bool handled)
    return processOutboundEvents();
}

bool NativeInputEventReceiver::probablyHasInput() {
bool NativeInputEventReceiver::probablyHasInput() const {
    if (mInputConsumer == nullptr) {
        return false;
    }
@@ -512,7 +514,11 @@ status_t NativeInputEventReceiver::consumeEvents(JNIEnv* env,
    }
}

std::string NativeInputEventReceiver::dump(const char* prefix) {
sp<IBinder> NativeInputEventReceiver::getInputChannelToken() const {
    return mInputConsumer->getChannel()->getConnectionToken();
}

std::string NativeInputEventReceiver::dump(const char* prefix) const {
    std::string out;
    std::string consumerDump =
            addPrefix(mInputConsumer != nullptr ? mInputConsumer->dump() : "<null>", "  ");
@@ -636,6 +642,12 @@ static jboolean nativeConsumeBatchedInputEvents(JNIEnv* env, jclass clazz, jlong
    return consumedBatch ? JNI_TRUE : JNI_FALSE;
}

static jobject nativeGetToken(JNIEnv* env, jclass clazz, jlong receiverPtr) {
    sp<NativeInputEventReceiver> receiver =
            reinterpret_cast<NativeInputEventReceiver*>(receiverPtr);
    return javaObjectForIBinder(env, receiver->getInputChannelToken());
}

static jstring nativeDump(JNIEnv* env, jclass clazz, jlong receiverPtr, jstring prefix) {
    sp<NativeInputEventReceiver> receiver =
            reinterpret_cast<NativeInputEventReceiver*>(receiverPtr);
@@ -653,6 +665,7 @@ static const JNINativeMethod gMethods[] = {
        {"nativeProbablyHasInput", "(J)Z", (void*)nativeProbablyHasInput},
        {"nativeReportTimeline", "(JIJJ)V", (void*)nativeReportTimeline},
        {"nativeConsumeBatchedInputEvents", "(JJ)Z", (void*)nativeConsumeBatchedInputEvents},
        {"nativeGetToken", "(J)Landroid/os/IBinder;", (void*)nativeGetToken},
        {"nativeDump", "(JLjava/lang/String;)Ljava/lang/String;", (void*)nativeDump},
};