SurfaceFlinger: use queueTime as well when calculating refresh rate

When calculating refresh rate, we want to make sure that the refresh
rate of a layer is "stable", meaning that the average we calculated
is correct for all the samples we have. If the app stops frame
production and then resumes we don't want to calculate the refresh
rate average across a different group of frames. This change enhances
the detection of when the app stops to produce a frame by looking at
the queue time of a frame if this frame doesn't have a timestamp.

Bug: 155710271
Test: Start an animation not driven by touch
Change-Id: Icef63a1ba86c1ad063592717115addd700e22cad
diff --git a/services/surfaceflinger/Scheduler/LayerInfoV2.cpp b/services/surfaceflinger/Scheduler/LayerInfoV2.cpp
index 44b4264..ce57ea8 100644
--- a/services/surfaceflinger/Scheduler/LayerInfoV2.cpp
+++ b/services/surfaceflinger/Scheduler/LayerInfoV2.cpp
@@ -130,12 +130,16 @@
     // Now once we calculated the refresh rate we need to make sure that all the frames we captured
     // are evenly distributed and we don't calculate the average across some burst of frames.
     for (auto it = mFrameTimes.begin(); it != mFrameTimes.end() - 1; ++it) {
-        if (it->presetTime == 0 || (it + 1)->presetTime == 0) {
-            continue;
-        }
-        const nsecs_t presentTimeDeltas =
-                std::max(((it + 1)->presetTime - it->presetTime), mHighRefreshRatePeriod);
-        if (std::abs(presentTimeDeltas - averageFrameTime) > 2 * averageFrameTime) {
+        const nsecs_t frameTimeDeltas = [&] {
+            nsecs_t delta;
+            if (it->presetTime == 0 || (it + 1)->presetTime == 0) {
+                delta = (it + 1)->queueTime - it->queueTime;
+            } else {
+                delta = (it + 1)->presetTime - it->presetTime;
+            }
+            return std::max(delta, mHighRefreshRatePeriod);
+        }();
+        if (std::abs(frameTimeDeltas - averageFrameTime) > 2 * averageFrameTime) {
             return std::nullopt;
         }
     }