Introduce thread safety to InputDeviceMetricsCollector

There are several threads that interact with the metrics collector, such
as the Reader thread, Dispatcher thread, and binder threads for
dumping.

However, thread safety was never added to it, since it started off only
running on the Reader thread. There is a high likelihood that this is
the root cause of crashes that we see when dumping the metrics
collector.

Add a lock to the metrics collector to guard its state.

Bug: 315193876
Test: atest inputflinger_tests
Change-Id: I6a53014fbc533cf15516e8b079ee5b715b4aa58f
3 files changed