Fix AlarmManager high CPU issue

- clampPositive assumes negative value is due to overflow and so sets
   to MAX_VALUE. However it also possible that negative value occurs
    due to addition of negative value(of higher magnitude) with positive
    of lower magnitude. In issue case, NTP sync causes RTC to move
    forward thus pushing whenElapsed to negative range. This means
    maxWhenElapsed would also be negative but is clamped to MAX_VALUE
    causing AlarmManager to go into infinite loop.

Bug: b/308389917
Test: manual
Change-Id: Ie12d5125f1feeeb1a5dd661a744f86d00796d126
Merged-In: I946333b86b2658ec1b70cb1e3110f5eae1b81486
2 files changed