Refactor KeyEvent constructors.

KeyEvent has about 10 fields and 10 constructors, and not all
constructors set all thse fields, which can cause issues (for
example, some constructors were setting the display id to
INVALID_DISPLAY, while others weren't - this was probably a mistake
introduced when the new constructors were added).

This CL defines 2 "canonical" constructors (one that only takes
individual parameters, another one that takes a KeyEvent) and
refactor the others to call one of them, which would make them less
error prone.

Notice that there are still some inconsistency on how some fields
are initially set (for example, mDeviceId is set to VIRTUAL_KEYBOARD
and source is set to SOURCE_KEYBOARD by some constructors but they're
left as 0 by others) - it's not the purpose of this CL to fix these
cases, but the new constructors (and unit tests) would make it easier
to do so in the future.

NOTE: this CL is similar to 1aa18e2f2197f96abe5e20ff3062c52f26900923
(which was reverted), but fixing the constructor that took characters.

Test: atest android.view.KeyEventTest CtsInputMethodTestCases:android.view.inputmethod.cts.FocusHandlingTest

Bug: 268103680
Fixes: 270247000

Change-Id: Ic5867212c827065fb14af164b5b90f4815162342
2 files changed