summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--services/sensorservice/SensorEventConnection.cpp20
-rw-r--r--services/sensorservice/SensorEventConnection.h2
2 files changed, 17 insertions, 5 deletions
diff --git a/services/sensorservice/SensorEventConnection.cpp b/services/sensorservice/SensorEventConnection.cpp
index 8dc80cce18..776efab19c 100644
--- a/services/sensorservice/SensorEventConnection.cpp
+++ b/services/sensorservice/SensorEventConnection.cpp
@@ -32,8 +32,9 @@ SensorService::SensorEventConnection::SensorEventConnection(
const String16& opPackageName, bool hasSensorAccess)
: mService(service), mUid(uid), mWakeLockRefCount(0), mHasLooperCallbacks(false),
mDead(false), mDataInjectionMode(isDataInjectionMode), mEventCache(nullptr),
- mCacheSize(0), mMaxCacheSize(0), mPackageName(packageName), mOpPackageName(opPackageName),
- mDestroyed(false), mHasSensorAccess(hasSensorAccess) {
+ mCacheSize(0), mMaxCacheSize(0), mTimeOfLastEventDrop(0), mEventsDropped(0),
+ mPackageName(packageName), mOpPackageName(opPackageName), mDestroyed(false),
+ mHasSensorAccess(hasSensorAccess) {
mChannel = new BitTube(mService->mSocketBufferSize);
#if DEBUG_CONNECTIONS
mEventsReceived = mEventsSentFromCache = mEventsSent = 0;
@@ -405,9 +406,6 @@ void SensorService::SensorEventConnection::appendEventsToCacheLocked(sensors_eve
reAllocateCacheLocked(events, count);
} else {
// The events do not fit within the cache: drop the oldest events.
- ALOGW("Dropping events from cache (%d / %d) to save %d newer events", mCacheSize,
- mMaxCacheSize, count);
-
int freeSpace = mMaxCacheSize - mCacheSize;
// Drop up to the currently cached number of events to make room for new events
@@ -419,6 +417,18 @@ void SensorService::SensorEventConnection::appendEventsToCacheLocked(sensors_eve
// Determine the number of new events to copy into the cache
int eventsToCopy = std::min(mMaxCacheSize, count);
+ constexpr nsecs_t kMinimumTimeBetweenDropLogNs = 2 * 1000 * 1000 * 1000; // 2 sec
+ if (events[0].timestamp - mTimeOfLastEventDrop > kMinimumTimeBetweenDropLogNs) {
+ ALOGW("Dropping %d cached events (%d/%d) to save %d/%d new events. %d events previously"
+ " dropped", cachedEventsToDrop, mCacheSize, mMaxCacheSize, eventsToCopy,
+ count, mEventsDropped);
+ mEventsDropped = 0;
+ mTimeOfLastEventDrop = events[0].timestamp;
+ } else {
+ // Record the number dropped
+ mEventsDropped += cachedEventsToDrop + newEventsToDrop;
+ }
+
// Check for any flush complete events in the events that will be dropped
countFlushCompleteEventsLocked(mEventCache, cachedEventsToDrop);
countFlushCompleteEventsLocked(events, newEventsToDrop);
diff --git a/services/sensorservice/SensorEventConnection.h b/services/sensorservice/SensorEventConnection.h
index eefd81a258..061809f363 100644
--- a/services/sensorservice/SensorEventConnection.h
+++ b/services/sensorservice/SensorEventConnection.h
@@ -165,6 +165,8 @@ private:
sensors_event_t *mEventCache;
int mCacheSize, mMaxCacheSize;
+ int64_t mTimeOfLastEventDrop;
+ int mEventsDropped;
String8 mPackageName;
const String16 mOpPackageName;
#if DEBUG_CONNECTIONS