Prevent overflow when caching sensor events

Ensure that the boundary of the SensorEventConnection's event cache is
not exceeded if more events need to be stored in the cache than there
is currently free capacity for.

Also resolves an issue where sensor events were not properly appended
to the end of the cache if events had to be dropped to fit the new
events.

Bug: 119501435
Test: Builds, forced events to be written to the cache and ensured the
      cache never exceeded its limits.
Change-Id: Ib3ed211dd42f47ea0e542687c07ed7106fcad1e7
2 files changed