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: I946333b86b2658ec1b70cb1e3110f5eae1b81486
2 files changed