SF: Adding statistical mode

- Adding statistical mode for timestamp intervals.
- Moving math calculations into util class, and adding a unit test.

See go/surface-flinger-scheduler for more info and systrace links.

Test: SF tests pass. Adding new test class.
Bug: 113612090
Change-Id: I3c3a73e3d8719e47326d8a48d27683037b7beb47
diff --git a/services/surfaceflinger/Scheduler/Scheduler.h b/services/surfaceflinger/Scheduler/Scheduler.h
index adfc071..764ad00 100644
--- a/services/surfaceflinger/Scheduler/Scheduler.h
+++ b/services/surfaceflinger/Scheduler/Scheduler.h
@@ -27,6 +27,7 @@
 #include "EventThread.h"
 #include "InjectVSyncSource.h"
 #include "LayerHistory.h"
+#include "SchedulerUtils.h"
 
 namespace android {
 
@@ -111,8 +112,6 @@
     void incrementFrameCounter();
 
 protected:
-    friend class SchedulerTest;
-
     virtual std::unique_ptr<EventThread> makeEventThread(
             const std::string& connectionName, DispSync* dispSync, int64_t phaseOffsetNs,
             impl::EventThread::ResyncWithRateLimitCallback resyncCallback,
@@ -124,9 +123,6 @@
     // Collects the statistical mean (average) and median between timestamp
     // intervals for each frame for each layer.
     void determineLayerTimestampStats(const std::string layerName, const nsecs_t framePresentTime);
-    // Calculates the statistical median in the vector. Return 0 if the vector is empty. The
-    // function modifies the vector contents.
-    int64_t calculateMedian(std::vector<int64_t>* v);
     // Collects the average difference between timestamps for each frame regardless
     // of which layer the timestamp came from.
     void determineTimestampAverage(bool isAutoTimestamp, const nsecs_t framePresentTime);
@@ -163,8 +159,7 @@
     // simulate 30Hz rendering, we skip every other frame, and this variable is set
     // to 1.
     int64_t mSkipCount = 0;
-    static constexpr size_t ARRAY_SIZE = 30;
-    std::array<int64_t, ARRAY_SIZE> mTimeDifferences;
+    std::array<int64_t, scheduler::ARRAY_SIZE> mTimeDifferences{};
     size_t mCounter = 0;
 
     LayerHistory mLayerHistory;