Refactor hid command, mitigate overflows

Currently there are a few overflows possible in the hid command by
sending malformed json requests. Refactor the code to avoid these
overflows. These are mostly memcpy usage, where the size comes
(indirectly) from the size of the json array.
The json array must still be valid, because invalid json will produce an
earlier exception in the java layer.

Test: hid malformed_commands.json
The file "malformed_commands.json" can be found in the bug.
Bug: 111363077

Merged-In: I2f9dd31e0bfa2badc58779f40f4a80e025754cd2
(cherry picked from commit d54b70c8bfe393ef57445bd59962e6730b0b13c0)
Change-Id: I2f9dd31e0bfa2badc58779f40f4a80e025754cd2
2 files changed