Merge "AlarmManagerService.setKernelTime: fix incorrect limit." am: c7bbb5914b
Change-Id: I0bf754fe11e2d2fc64b3d6f87b1d7435abe8471e
This commit is contained in:
@@ -40,6 +40,7 @@
|
|||||||
#include <linux/rtc.h>
|
#include <linux/rtc.h>
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <limits>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace android {
|
namespace android {
|
||||||
@@ -213,22 +214,20 @@ int AlarmImpl::waitForAlarm()
|
|||||||
static jint android_server_AlarmManagerService_setKernelTime(JNIEnv*, jobject, jlong nativeData, jlong millis)
|
static jint android_server_AlarmManagerService_setKernelTime(JNIEnv*, jobject, jlong nativeData, jlong millis)
|
||||||
{
|
{
|
||||||
AlarmImpl *impl = reinterpret_cast<AlarmImpl *>(nativeData);
|
AlarmImpl *impl = reinterpret_cast<AlarmImpl *>(nativeData);
|
||||||
struct timeval tv;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (millis <= 0 || millis / 1000LL >= INT_MAX) {
|
if (millis <= 0 || millis / 1000LL >= std::numeric_limits<time_t>::max()) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
tv.tv_sec = (time_t) (millis / 1000LL);
|
struct timeval tv;
|
||||||
tv.tv_usec = (suseconds_t) ((millis % 1000LL) * 1000LL);
|
tv.tv_sec = (millis / 1000LL);
|
||||||
|
tv.tv_usec = ((millis % 1000LL) * 1000LL);
|
||||||
|
|
||||||
ALOGD("Setting time of day to sec=%d\n", (int) tv.tv_sec);
|
ALOGD("Setting time of day to sec=%ld", tv.tv_sec);
|
||||||
|
|
||||||
ret = impl->setTime(&tv);
|
|
||||||
|
|
||||||
|
int ret = impl->setTime(&tv);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
ALOGW("Unable to set rtc to %ld: %s\n", tv.tv_sec, strerror(errno));
|
ALOGW("Unable to set rtc to %ld: %s", tv.tv_sec, strerror(errno));
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
Reference in New Issue
Block a user