Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2324e98a authored by Suprabh Shukla's avatar Suprabh Shukla
Browse files

Adding next kernel alarm time to alarm dumpsys

Adding a native method to query timerfd_gettime. This is helpful in
debugging because it will tell for certain whether the kernel timer was
armed or not and whether it matches the expectation of higher level code
in the service.

Test: adb shell dumpsys alarm

Bug: 78560047
Change-Id: If08ebf69b0bde7e8f504d81b98e3f41ecf7f2dc2
parent ac809dc4
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -1953,6 +1953,14 @@ class AlarmManagerService extends SystemService {
                    pw.print(" = "); pw.println(sdf.format(new Date(nextWakeupRTC)));
            pw.print("    set at "); TimeUtils.formatDuration(mLastWakeupSet, nowELAPSED, pw);
                    pw.println();

            pw.print("  Next kernel non-wakeup alarm: ");
            TimeUtils.formatDuration(getNextAlarm(mNativeData, ELAPSED_REALTIME), pw);
            pw.println();
            pw.print("  Next kernel wakeup alarm: ");
            TimeUtils.formatDuration(getNextAlarm(mNativeData, ELAPSED_REALTIME_WAKEUP), pw);
            pw.println();

            pw.print("  Last wakeup: "); TimeUtils.formatDuration(mLastWakeup, nowELAPSED, pw);
                    pw.print(" = "); pw.println(mLastWakeup);
            pw.print("  Last trigger: "); TimeUtils.formatDuration(mLastTrigger, nowELAPSED, pw);
@@ -3063,6 +3071,7 @@ class AlarmManagerService extends SystemService {
    private native int waitForAlarm(long nativeData);
    private native int setKernelTime(long nativeData, long millis);
    private native int setKernelTimezone(long nativeData, int minuteswest);
    private native long getNextAlarm(long nativeData, int type);

    private long getWhileIdleMinIntervalLocked(int uid) {
        final boolean dozing = mPendingIdleUntil != null;
+29 −0
Original line number Diff line number Diff line
@@ -81,6 +81,7 @@ public:
    int set(int type, struct timespec *ts);
    int setTime(struct timeval *tv);
    int waitForAlarm();
    int getTime(int type, struct itimerspec *spec);

private:
    const TimerFds fds;
@@ -118,6 +119,16 @@ int AlarmImpl::set(int type, struct timespec *ts)
    return timerfd_settime(fds[type], TFD_TIMER_ABSTIME, &spec, NULL);
}

int AlarmImpl::getTime(int type, struct itimerspec *spec)
{
    if (static_cast<size_t>(type) > ANDROID_ALARM_TYPE_COUNT) {
        errno = EINVAL;
        return -1;
    }

    return timerfd_gettime(fds[type], spec);
}

int AlarmImpl::setTime(struct timeval *tv)
{
    struct rtc_time rtc;
@@ -379,6 +390,23 @@ static jlong android_server_AlarmManagerService_init(JNIEnv*, jobject)
    return reinterpret_cast<jlong>(ret);
}

static jlong android_server_AlarmManagerService_getNextAlarm(JNIEnv*, jobject, jlong nativeData, jint type)
{
    AlarmImpl *impl = reinterpret_cast<AlarmImpl *>(nativeData);
    struct itimerspec spec;
    memset(&spec, 0, sizeof(spec));
    const int result = impl->getTime(type, &spec);
    if (result < 0)
    {
        ALOGE("timerfd_gettime() failed for fd %d: %s\n", static_cast<int>(type), strerror(errno));
        return result;
    }
    struct timespec nextTimespec = spec.it_value;
    long long millis = nextTimespec.tv_sec * 1000LL;
    millis += (nextTimespec.tv_nsec / 1000000LL);
    return static_cast<jlong>(millis);
}

static void android_server_AlarmManagerService_close(JNIEnv*, jobject, jlong nativeData)
{
    AlarmImpl *impl = reinterpret_cast<AlarmImpl *>(nativeData);
@@ -429,6 +457,7 @@ static const JNINativeMethod sMethods[] = {
    {"waitForAlarm", "(J)I", (void*)android_server_AlarmManagerService_waitForAlarm},
    {"setKernelTime", "(JJ)I", (void*)android_server_AlarmManagerService_setKernelTime},
    {"setKernelTimezone", "(JI)I", (void*)android_server_AlarmManagerService_setKernelTimezone},
    {"getNextAlarm", "(JI)J", (void*)android_server_AlarmManagerService_getNextAlarm},
};

int register_android_server_AlarmManagerService(JNIEnv* env)