Snap for 10843824 from d8625365ec20038cb8fd0fc093b88dd461529d98 to 24Q1-release

Change-Id: I104ca18341c1af644befd703711ee870aa2ed3c3
diff --git a/modules/gralloc/gr.h b/modules/gralloc/gr.h
index 14fe6a0..fe66c9b 100644
--- a/modules/gralloc/gr.h
+++ b/modules/gralloc/gr.h
@@ -24,6 +24,7 @@
 #include <hardware/gralloc.h>
 #include <pthread.h>
 #include <errno.h>
+#include <unistd.h>
 
 #include <cutils/native_handle.h>
 
@@ -32,8 +33,10 @@
 struct private_module_t;
 struct private_handle_t;
 
+static const size_t kPageSize = getpagesize();
+
 inline size_t roundUpToPageSize(size_t x) {
-    return (x + (PAGE_SIZE-1)) & ~(PAGE_SIZE-1);
+    return (x + (kPageSize-1)) & ~(kPageSize-1);
 }
 
 int mapFrameBufferLocked(struct private_module_t* module, int format);
diff --git a/modules/sensors/dynamic_sensor/HidRawSensorDevice.cpp b/modules/sensors/dynamic_sensor/HidRawSensorDevice.cpp
index 8aa4cf9..5bc4abc 100644
--- a/modules/sensors/dynamic_sensor/HidRawSensorDevice.cpp
+++ b/modules/sensors/dynamic_sensor/HidRawSensorDevice.cpp
@@ -35,6 +35,15 @@
 const std::unordered_set<unsigned int> HidRawSensorDevice::sInterested{
         ACCELEROMETER_3D, GYROMETER_3D, COMPASS_3D, CUSTOM};
 
+void HidRawSensorDevice::enableSchedFifoMode() {
+  constexpr int kHidRawSensorPriority = 10;  // Matches with sensor service priority
+  struct sched_param param = {0};
+  param.sched_priority = kHidRawSensorPriority;
+  if (sched_setscheduler(getTid(), SCHED_FIFO | SCHED_RESET_ON_FORK, &param) != 0) {
+    ALOGE("Couldn't set SCHED_FIFO for HidRawSensor thread: %s", strerror(errno));
+  }
+}
+
 sp<HidRawSensorDevice> HidRawSensorDevice::create(const std::string &devName) {
     sp<HidRawSensorDevice> device(new HidRawSensorDevice(devName));
     // offset +1 strong count added by constructor
@@ -74,7 +83,8 @@
         return;
     }
 
-    run("HidRawSensor");
+    run("HidRawSensor", PRIORITY_URGENT_DISPLAY);
+    enableSchedFifoMode();
     mValid = true;
 }
 
diff --git a/modules/sensors/dynamic_sensor/HidRawSensorDevice.h b/modules/sensors/dynamic_sensor/HidRawSensorDevice.h
index 06d435e..7818bf1 100644
--- a/modules/sensors/dynamic_sensor/HidRawSensorDevice.h
+++ b/modules/sensors/dynamic_sensor/HidRawSensorDevice.h
@@ -41,6 +41,7 @@
 
     // constructor will result in +1 strong count
     explicit HidRawSensorDevice(const std::string &devName);
+    void enableSchedFifoMode();
     // implement function of Thread
     virtual bool threadLoop() override;
     std::unordered_map<unsigned int/*reportId*/, sp<HidRawSensor>> mSensors;