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
diff --git a/services/sensorservice/SensorEventConnection.h b/services/sensorservice/SensorEventConnection.h
index 40c21ff..eefd81a 100644
--- a/services/sensorservice/SensorEventConnection.h
+++ b/services/sensorservice/SensorEventConnection.h
@@ -108,6 +108,10 @@
     // size, reallocate memory and copy over events from the older cache.
     void reAllocateCacheLocked(sensors_event_t const* scratch, int count);
 
+    // Add the events to the cache. If the cache would be exceeded, drop events at the beginning of
+    // the cache.
+    void appendEventsToCacheLocked(sensors_event_t const* events, int count);
+
     // LooperCallback method. If there is data to read on this fd, it is an ack from the app that it
     // has read events from a wake up sensor, decrement mWakeLockRefCount.  If this fd is available
     // for writing send the data from the cache.