diff options
author | Andrew Rossignol <aarossig@google.com> | 2017-01-31 14:06:36 -0800 |
---|---|---|
committer | Andrew Rossignol <aarossig@google.com> | 2017-01-31 17:30:11 -0800 |
commit | c77d0b6294d47fb26e942b4f0281f148191da6c9 (patch) | |
tree | a62d453e977e5bc8c7b479ba7e8d3849d12e419b | |
parent | c9878baf251f62f9887a6ec8a735ae5d0a3fc89e (diff) | |
download | contexthub-android-7.1.2_r27.tar.gz |
Add support for detecting old unpublished AR events to discard themandroid-7.1.2_r9android-7.1.2_r8android-7.1.2_r6android-7.1.2_r5android-7.1.2_r4android-7.1.2_r39android-7.1.2_r38android-7.1.2_r37android-7.1.2_r36android-7.1.2_r33android-7.1.2_r32android-7.1.2_r30android-7.1.2_r3android-7.1.2_r29android-7.1.2_r28android-7.1.2_r27android-7.1.2_r25android-7.1.2_r24android-7.1.2_r23android-7.1.2_r2android-7.1.2_r19android-7.1.2_r18android-7.1.2_r17android-7.1.2_r16android-7.1.2_r15android-7.1.2_r14android-7.1.2_r13android-7.1.2_r12android-7.1.2_r11android-7.1.2_r10android-7.1.2_r1nougat-mr2.3-releasenougat-mr2.2-releasenougat-mr2.1-releasenougat-mr2-security-releasenougat-mr2-releasenougat-mr2-pixel-releasenougat-mr2-dev
Bug: 34801522
Change-Id: Icbc2ea4f2219b71adb4a93b65de36fcd1480321f
-rw-r--r-- | sensorhal/activity.cpp | 38 | ||||
-rw-r--r-- | sensorhal/activity.h | 4 |
2 files changed, 41 insertions, 1 deletions
diff --git a/sensorhal/activity.cpp b/sensorhal/activity.cpp index df7ea042..491266b1 100644 --- a/sensorhal/activity.cpp +++ b/sensorhal/activity.cpp @@ -32,6 +32,7 @@ static const int kVersionMinor = 0; // The maximum delta between events at which point their timestamps are to be // considered equal. static const int64_t kEventTimestampThresholdNanos = 100000000; // 100ms. +static const int64_t kMaxEventAgeNanos = 10000000000; // 10000ms. static const useconds_t kFlushDelayMicros = 10000; // 10ms. static const char *const kActivityList[] = { @@ -202,6 +203,40 @@ void ActivityContext::PublishEvent(const ActivityEvent& event) { mNewestPublishedEventIndexIsKnown = true; } +void ActivityContext::DiscardExpiredUnpublishedEvents(uint64_t whenNs) { + // Determine the current oldest buffered event. + uint64_t oldestEventTimestamp = UINT64_MAX; + for (size_t i = 0; i < mUnpublishedEvents.size(); i++) { + const ActivityEvent *event = &mUnpublishedEvents[i]; + if (event->whenNs < oldestEventTimestamp) { + oldestEventTimestamp = event->whenNs; + } + } + + // If the age of the oldest buffered event is too large an AR sample + // has been lost. When this happens all AR transitions are set to + // ACTIVITY_EVENT_EXIT and the event ordering logic is reset. + if (oldestEventTimestamp != UINT64_MAX + && (whenNs - oldestEventTimestamp) > kMaxEventAgeNanos) { + ALOGD("Lost event detected, discarding buffered events"); + + // Publish stop events for all activity types except for TILTING. + for (uint32_t activity = 0; + activity < (ARRAY_SIZE(kActivityList) - 1); activity++) { + activity_event_t halEvent; + memset(&halEvent, 0, sizeof(halEvent)); + + halEvent.activity = activity; + halEvent.timestamp = oldestEventTimestamp; + halEvent.event_type = ACTIVITY_EVENT_EXIT; + (*mCallback->activity_callback)(mCallback, &halEvent, 1); + } + + // Reset the event reordering logic. + OnSensorHubReset(); + } +} + void ActivityContext::OnActivityEvent(int sensorIndex, uint8_t eventIndex, uint64_t whenNs) { ALOGD("OnActivityEvent sensorIndex = %d, eventIndex = %" PRIu8 @@ -212,6 +247,8 @@ void ActivityContext::OnActivityEvent(int sensorIndex, uint8_t eventIndex, return; } + DiscardExpiredUnpublishedEvents(whenNs); + ActivityEvent event = { .eventIndex = eventIndex, .sensorIndex = sensorIndex, @@ -335,7 +372,6 @@ int ActivityContext::flush() { // used here to control the lifecycle of the lock as OnFlush may be // invoked before this method returns. Mutex::Autolock autoLock(mCallbackLock); - mOutstandingFlushEvents += (COMMS_SENSOR_ACTIVITY_LAST - COMMS_SENSOR_ACTIVITY_FIRST) + 1; } diff --git a/sensorhal/activity.h b/sensorhal/activity.h index 67a1954c..1d5fa5e3 100644 --- a/sensorhal/activity.h +++ b/sensorhal/activity.h @@ -96,6 +96,10 @@ class ActivityContext : public ActivityEventHandler { // Publishes an AR event to the AR HAL client. void PublishEvent(const ActivityEvent& event); + // Searches for very old AR events, discards them and publishes EVENT_EXIT + // transitions for all activities. + void DiscardExpiredUnpublishedEvents(uint64_t whenNs); + DISALLOW_EVIL_CONSTRUCTORS(ActivityContext); }; |