Store time in nanoseconds in KeyEvent
KeyEvent today stores time in milliseconds. That means that data is lost when it gets sent from native to Java layers. The subsequent return route, going from Java to native, cannot recover this data. This causes the KeyEvents to have truncated event times when they are inspected by InputDispatcher (for example, for injectInputEvent and verifyInputEvent apis). In the injectInputEvent, this is fine, because the public api to create a KeyEvent does not allow the caller to provide nanoseconds. For the verifyInputEvent, however, this is a problem. When the HMAC of the provided KeyEvent is computed, it no longer matches the HMAC of the original KeyEvent. That means that verification for KeyEvents is broken. To fix this, we pass nanosecond values to Java layer. The fields are already stored as 'long', so there's enough room for that. To maintain the existing api behaviour, though, we need to convert to/from milliseconds at the public api bondary. This specifically applies to KeyEvent constructors, some of the 'obtain' apis, and 'getDownTime'/'getEventTime' apis. Test: atest VerifyHardwareKeyEventTest Bug: 194264616 Change-Id: I0c82a2f065bc947a0e48a26ae3ea5f4ef77f464f
Loading
Please register or sign in to comment