SF: Update InputFlinger outside main thread

Avoids parceling data inside  main thread and hot path. Also
avoids any binder contention with one way binder calls. See
bug for more details.

Re landing with the following changes:
Don't discard input commands if input dispatcher is not
available. This can happen if system server crashes and
recovers. We want to keep input commands until
input dispatcher becomes available.

Bug: 206380308
Test: presubmit
Test: systrace
Test: flickertests
Test: health/microbench/display/microbench-test-suite
Change-Id: If0344abdeb28c8a409eb2f641c1e78d53e6f59b2
diff --git a/services/surfaceflinger/BackgroundExecutor.cpp b/services/surfaceflinger/BackgroundExecutor.cpp
index 3663cdb..de8e6b3 100644
--- a/services/surfaceflinger/BackgroundExecutor.cpp
+++ b/services/surfaceflinger/BackgroundExecutor.cpp
@@ -32,7 +32,9 @@
             std::vector<std::function<void()>> tasks;
             {
                 std::unique_lock lock(mMutex);
-                mWorkAvailableCv.wait(lock, [&]() { return mDone || !mTasks.empty(); });
+                android::base::ScopedLockAssertion assumeLock(mMutex);
+                mWorkAvailableCv.wait(lock,
+                                      [&]() REQUIRES(mMutex) { return mDone || !mTasks.empty(); });
                 tasks = std::move(mTasks);
                 mTasks.clear();
                 done = mDone;
@@ -47,7 +49,7 @@
 
 BackgroundExecutor::~BackgroundExecutor() {
     {
-        std::unique_lock lock(mMutex);
+        std::scoped_lock lock(mMutex);
         mDone = true;
         mWorkAvailableCv.notify_all();
     }
@@ -57,7 +59,7 @@
 }
 
 void BackgroundExecutor::execute(std::function<void()> task) {
-    std::unique_lock lock(mMutex);
+    std::scoped_lock lock(mMutex);
     mTasks.emplace_back(std::move(task));
     mWorkAvailableCv.notify_all();
 }