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

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

Use <chrono> for injectInputEvent timeout

To avoid mistakes in units when calling input api's, convert
injectInputEvent timeout parameter to use std::chrono::duration.

Test: atest inputflinger_tests libinput_tests inputflinger_benchmarks
Bug: 143459140
Change-Id: I1eacdc16fa9b463492c052701cd3c7773686e448
parent 1255a2d2
Loading
Loading
Loading
Loading
+14 −6
Original line number Diff line number Diff line
@@ -1453,9 +1453,13 @@ static jint nativeInjectInputEvent(JNIEnv* env, jclass /* clazz */,
            return INPUT_EVENT_INJECTION_FAILED;
        }

        return (jint) im->getInputManager()->getDispatcher()->injectInputEvent(
                & keyEvent, injectorPid, injectorUid, syncMode, timeoutMillis,
        const int32_t result =
                im->getInputManager()->getDispatcher()->injectInputEvent(&keyEvent, injectorPid,
                                                                         injectorUid, syncMode,
                                                                         std::chrono::milliseconds(
                                                                                 timeoutMillis),
                                                                         uint32_t(policyFlags));
        return static_cast<jint>(result);
    } else if (env->IsInstanceOf(inputEventObj, gMotionEventClassInfo.clazz)) {
        const MotionEvent* motionEvent = android_view_MotionEvent_getNativePtr(env, inputEventObj);
        if (!motionEvent) {
@@ -1463,9 +1467,13 @@ static jint nativeInjectInputEvent(JNIEnv* env, jclass /* clazz */,
            return INPUT_EVENT_INJECTION_FAILED;
        }

        return (jint) im->getInputManager()->getDispatcher()->injectInputEvent(
                motionEvent, injectorPid, injectorUid, syncMode, timeoutMillis,
        const int32_t result =
                (jint)im->getInputManager()
                        ->getDispatcher()
                        ->injectInputEvent(motionEvent, injectorPid, injectorUid, syncMode,
                                           std::chrono::milliseconds(timeoutMillis),
                                           uint32_t(policyFlags));
        return static_cast<jint>(result);
    } else {
        jniThrowRuntimeException(env, "Invalid input event type.");
        return INPUT_EVENT_INJECTION_FAILED;