reupload^2: libsnapshot: set thread priority

It looks like the previous error was due to a missing include that
somehow my LSP didn't catch. The build failure isn't reproducible on
aosp-main but is on git_main. Confirmed this new patch with the #include
builds correctly on git_main.

Read merge thread + worker thread priority from build configurations. In
the case of low memory devices, a lower priority will reduce CPU
utilization post OTA reboot.

Test: th
Change-Id: I7fd398c4688cf78abe738e7320b9f27f5f7d1e13
diff --git a/fs_mgr/libsnapshot/snapuserd/user-space-merge/merge_worker.cpp b/fs_mgr/libsnapshot/snapuserd/user-space-merge/merge_worker.cpp
index bd7eaca..e6a9a29 100644
--- a/fs_mgr/libsnapshot/snapuserd/user-space-merge/merge_worker.cpp
+++ b/fs_mgr/libsnapshot/snapuserd/user-space-merge/merge_worker.cpp
@@ -17,6 +17,8 @@
 #include <libsnapshot/cow_format.h>
 #include <pthread.h>
 
+#include <android-base/properties.h>
+
 #include "merge_worker.h"
 #include "snapuserd_core.h"
 #include "utility.h"
@@ -179,8 +181,8 @@
         bufsink_.ResetBufferOffset();
 
         if (snapuserd_->IsIOTerminated()) {
-            SNAP_LOG(ERROR)
-                    << "MergeReplaceZeroOps: MergeWorker threads terminated - shutting down merge";
+            SNAP_LOG(ERROR) << "MergeReplaceZeroOps: MergeWorker threads terminated - shutting "
+                               "down merge";
             return false;
         }
     }
@@ -577,8 +579,10 @@
         SNAP_LOG(ERROR) << "Merge terminated early...";
         return true;
     }
+    auto merge_thread_priority = android::base::GetUintProperty<uint32_t>(
+            "ro.virtual_ab.merge_thread_priority", ANDROID_PRIORITY_BACKGROUND);
 
-    if (!SetThreadPriority(ANDROID_PRIORITY_BACKGROUND)) {
+    if (!SetThreadPriority(merge_thread_priority)) {
         SNAP_PLOG(ERROR) << "Failed to set thread priority";
     }
 
diff --git a/fs_mgr/libsnapshot/snapuserd/user-space-merge/read_worker.cpp b/fs_mgr/libsnapshot/snapuserd/user-space-merge/read_worker.cpp
index d40b6d1..ef311d4 100644
--- a/fs_mgr/libsnapshot/snapuserd/user-space-merge/read_worker.cpp
+++ b/fs_mgr/libsnapshot/snapuserd/user-space-merge/read_worker.cpp
@@ -14,11 +14,14 @@
  * limitations under the License.
  */
 
+#include <android-base/properties.h>
+
 #include <libsnapshot/cow_format.h>
 #include <pthread.h>
 
 #include "read_worker.h"
 #include "snapuserd_core.h"
+#include "user-space-merge/worker.h"
 #include "utility.h"
 
 namespace android {
@@ -259,8 +262,10 @@
     SNAP_LOG(INFO) << "Processing snapshot I/O requests....";
 
     pthread_setname_np(pthread_self(), "ReadWorker");
+    auto worker_thread_priority = android::base::GetUintProperty<uint32_t>(
+            "ro.virtual_ab.worker_thread_priority", ANDROID_PRIORITY_NORMAL);
 
-    if (!SetThreadPriority(ANDROID_PRIORITY_NORMAL)) {
+    if (!SetThreadPriority(worker_thread_priority)) {
         SNAP_PLOG(ERROR) << "Failed to set thread priority";
     }