SurfaceFlinger: Add touch events to Scheduler

Add the notion of Touch Events to Scheduler to enhance the algorithm
to move to Performance refresh rate.
Scheduler selects Performance when:
 - There is a touch event
 - There is a buffer to HWC

This change also removes the behavior of Scheduler to move to Performance
on Choreographer callbacks.

Test: Switch between apps using gesture navigation
Bug: 131906818
Change-Id: I588cfc32449e87744e829dc7c5261a2e4151a8f8
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 3f2240e..820ccc5 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -113,6 +113,7 @@
 #include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h>
 #include <android/hardware/configstore/1.1/ISurfaceFlingerConfigs.h>
 #include <android/hardware/configstore/1.1/types.h>
+#include <android/hardware/power/1.0/IPower.h>
 #include <configstore/Utils.h>
 
 #include <layerproto/LayerProtoParser.h>
@@ -124,6 +125,7 @@
 using namespace android::hardware::configstore::V1_0;
 using namespace android::sysprop;
 
+using android::hardware::power::V1_0::PowerHint;
 using base::StringAppendF;
 using ui::ColorMode;
 using ui::Dataspace;
@@ -985,7 +987,7 @@
     if (mCheckPendingFence) {
         if (previousFrameMissed()) {
             // fence has not signaled yet. wait for the next invalidate
-            mEventQueue->invalidateForHWC();
+            mEventQueue->invalidate();
             return true;
         }
 
@@ -1036,7 +1038,7 @@
 
     // we need to submit an empty frame to HWC to start the process
     mCheckPendingFence = true;
-    mEventQueue->invalidateForHWC();
+    mEventQueue->invalidate();
     return false;
 }
 
@@ -1332,6 +1334,16 @@
     return getHwComposer().setDisplayBrightness(*displayId, brightness);
 }
 
+status_t SurfaceFlinger::notifyPowerHint(int32_t hintId) {
+    PowerHint powerHint = static_cast<PowerHint>(hintId);
+
+    if (powerHint == PowerHint::INTERACTION) {
+        mScheduler->notifyTouchEvent();
+    }
+
+    return NO_ERROR;
+}
+
 // ----------------------------------------------------------------------------
 
 sp<IDisplayEventConnection> SurfaceFlinger::createDisplayEventConnection(
@@ -1354,10 +1366,12 @@
 }
 
 void SurfaceFlinger::signalTransaction() {
+    mScheduler->resetIdleTimer();
     mEventQueue->invalidate();
 }
 
 void SurfaceFlinger::signalLayerUpdate() {
+    mScheduler->resetIdleTimer();
     mEventQueue->invalidate();
 }
 
@@ -5034,7 +5048,8 @@
         case SET_POWER_MODE:
         case GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES:
         case SET_DISPLAY_CONTENT_SAMPLING_ENABLED:
-        case GET_DISPLAYED_CONTENT_SAMPLE: {
+        case GET_DISPLAYED_CONTENT_SAMPLE:
+        case NOTIFY_POWER_HINT: {
             if (!callingThreadHasUnscopedSurfaceFlingerAccess()) {
                 IPCThreadState* ipc = IPCThreadState::self();
                 ALOGE("Permission Denial: can't access SurfaceFlinger pid=%d, uid=%d",
@@ -5473,7 +5488,7 @@
 
 void SurfaceFlinger::repaintEverythingForHWC() {
     mRepaintEverything = true;
-    mEventQueue->invalidateForHWC();
+    mEventQueue->invalidate();
 }
 
 // A simple RAII class to disconnect from an ANativeWindow* when it goes out of scope