Making timerfd non-blocking in alarm manager.

Alarm manager uses timerfd with epoll_wait, so there can be a race where
read blocks if timerfd_settime was called after epoll_wait returns and
before read is called. Since epoll_wait returned, we should be treating
that as sufficient signal that the timer expired.
In general, it should be better to have a non-blocking fd with
epoll_wait as the kernel holds a wakelock until the next epoll_wait and
if we move the timer to the future the system should be waiting inside
epoll_wait and not inside read, to allow the system to go into suspend.

This is also expected to mitigate or eliminate cases where we are seeing
alarm delivery stuck while the system is stuck somewhere in read, while
the higher level code keeps waiting for it to return.

Test: builds, boots, existing tests pass:
atest CtsAlarmManagerTestCases

Bug: 78560047
Change-Id: Idbb3bf94b7e750686701757d2d27ad2d3246294f
diff --git a/services/core/java/com/android/server/AlarmManagerService.java b/services/core/java/com/android/server/AlarmManagerService.java
index 7185f02..26ef42f 100644
--- a/services/core/java/com/android/server/AlarmManagerService.java
+++ b/services/core/java/com/android/server/AlarmManagerService.java
@@ -3518,9 +3518,13 @@
 
     private class AlarmThread extends Thread
     {
+        private int mFalseWakeups;
+        private int mWtfThreshold;
         public AlarmThread()
         {
             super("AlarmManager");
+            mFalseWakeups = 0;
+            mWtfThreshold = 10;
         }
 
         public void run()
@@ -3633,6 +3637,17 @@
                                 }
                                 mPendingNonWakeupAlarms.clear();
                             }
+                            if (mLastTimeChangeRealtime != nowELAPSED && triggerList.isEmpty()) {
+                                if (++mFalseWakeups >= mWtfThreshold) {
+                                    Slog.wtf(TAG, "Too many (" + mFalseWakeups
+                                            + ") false wakeups, nowElapsed=" + nowELAPSED);
+                                    if (mWtfThreshold < 100_000) {
+                                        mWtfThreshold *= 10;
+                                    } else {
+                                        mFalseWakeups = 0;
+                                    }
+                                }
+                            }
                             final ArraySet<Pair<String, Integer>> triggerPackages =
                                     new ArraySet<>();
                             for (int i = 0; i < triggerList.size(); i++) {