From b2cba9ef0f1417881cc49a0498e185a068ad8c10 Mon Sep 17 00:00:00 2001
From: Solti Ho <solti@google.com>
Date: Sun, 11 Feb 2024 19:49:01 +0000
Subject: [PATCH] Revert "uinput: delay from the end of the last delay"

Revert submission 26154399

Reason for revert: b/324707605

Reverted changes: /q/submissionid:26154399

Change-Id: Ib4ab9a80e74ad5bfec005dd2744458a60bdedde1
---
 cmds/uinput/README.md                                   | 3 +--
 cmds/uinput/src/com/android/commands/uinput/Device.java | 3 ++-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/cmds/uinput/README.md b/cmds/uinput/README.md
index f1775864aca0..b6e4e0de8cf7 100644
--- a/cmds/uinput/README.md
+++ b/cmds/uinput/README.md
@@ -154,8 +154,7 @@ will be unregistered. There is no explicit command for unregistering a device.
 
 #### `delay`
 
-Add a delay between the processing of commands. The delay will be timed from when the last delay
-ended, rather than from the current time, to allow for more precise timings to be produced.
+Add a delay to command processing
 
 | Field         | Type          | Description                |
 |:-------------:|:-------------:|:-------------------------- |
diff --git a/cmds/uinput/src/com/android/commands/uinput/Device.java b/cmds/uinput/src/com/android/commands/uinput/Device.java
index d786da2b98e7..853051a0be7b 100644
--- a/cmds/uinput/src/com/android/commands/uinput/Device.java
+++ b/cmds/uinput/src/com/android/commands/uinput/Device.java
@@ -149,7 +149,8 @@ public class Device {
      * @param delayNanos  Time to delay in unit of nanoseconds.
      */
     public void addDelayNanos(long delayNanos) {
-        mTimeToSendNanos += delayNanos;
+        mTimeToSendNanos =
+                Math.max(SystemClock.uptimeNanos(), mTimeToSendNanos) + delayNanos;
     }
 
     /**
-- 
GitLab