configstore: remove build flags from surfaceflinger

This change removes build flags used in building surfaceflinger.
Instead, surfaceflinger uses android.hardware.configstore HAL to get
values for the build flags at runtime.

As a first attempt, a build flag VSYNC_VENT_PHASE_OFFSET_NS is converted
to a hwbinder call to vsyncEventPhaseoffsetNs() function in
android.hardware.configstore@1.0 package.

Note that VSYNC_EVENT_PHASE_OFFSET_NS still remains in Android.mk
for non-treble targets.

Design doc: go/design-confighal
Bug: 34314793
Test: build, run, log message "Phase offset NS: ..." should be seen.

Change-Id: I43862d4df5abd3e9275ec9c0e2e0b568d8b48347
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 5f25ef5..e4e1ee8 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -81,6 +81,8 @@
 #include "RenderEngine/RenderEngine.h"
 #include <cutils/compiler.h>
 
+#include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h>
+
 #define DISPLAY_COUNT       1
 
 /*
@@ -93,6 +95,22 @@
 
 namespace android {
 
+using namespace android::hardware::configstore::V1_0;
+
+static sp<ISurfaceFlingerConfigs> getConfigs() {
+    static sp<ISurfaceFlingerConfigs> configs
+            = ISurfaceFlingerConfigs::getService();
+    return configs;
+}
+
+static int64_t getVsyncEventPhaseOffsetNs() {
+    int64_t ret = 1000000; // default value
+    getConfigs()->vsyncEventPhaseOffsetNs([&](OptionalInt64 value) {
+          if (value.specified) ret = value.value;
+    });
+    return ret;
+}
+
 // This is the phase offset in nanoseconds of the software vsync event
 // relative to the vsync event reported by HWComposer.  The software vsync
 // event is when SurfaceFlinger and Choreographer-based applications run each
@@ -113,7 +131,7 @@
 // the latency will end up being an additional vsync period, and animations
 // will hiccup.  Therefore, this latency should be tuned somewhat
 // conservatively (or at least with awareness of the trade-off being made).
-static const int64_t vsyncPhaseOffsetNs = VSYNC_EVENT_PHASE_OFFSET_NS;
+static int64_t vsyncPhaseOffsetNs = getVsyncEventPhaseOffsetNs();
 
 // This is the phase offset at which SurfaceFlinger's composition runs.
 static const int64_t sfVsyncPhaseOffsetNs = SF_VSYNC_EVENT_PHASE_OFFSET_NS;
@@ -484,6 +502,8 @@
     ALOGI(  "SurfaceFlinger's main thread ready to run. "
             "Initializing graphics H/W...");
 
+    ALOGI("Phase offest NS: %" PRId64 "", vsyncPhaseOffsetNs);
+
     { // Autolock scope
         Mutex::Autolock _l(mStateLock);
 
@@ -664,7 +684,7 @@
         info.xdpi = xdpi;
         info.ydpi = ydpi;
         info.fps = 1e9 / hwConfig->getVsyncPeriod();
-        info.appVsyncOffset = VSYNC_EVENT_PHASE_OFFSET_NS;
+        info.appVsyncOffset = vsyncPhaseOffsetNs;
 
         // This is how far in advance a buffer must be queued for
         // presentation at a given time.  If you want a buffer to appear