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

Commit c94c0518 authored by Jae Seo's avatar Jae Seo
Browse files

TIF: Use System.nanoTime() to measure execution durations in sessions

When the wall clock is adjusted to the broadcast time, the duration
measurement in ITvInputSessionWrapper may go wrong. To avoid this, use
System.nanoTime() that doesn't depend on the wall clock.

Bug: 25370822
Change-Id: I2ddb968b5e146500429b82979fe48262bf335993
parent 7e13a483
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -87,7 +87,7 @@ public class ITvInputSessionWrapper extends ITvInputSession.Stub implements Hand
            return;
        }

        long startTime = System.currentTimeMillis();
        long startTime = System.nanoTime();
        switch (msg.what) {
            case DO_RELEASE: {
                mTvInputSessionImpl.release();
@@ -185,18 +185,18 @@ public class ITvInputSessionWrapper extends ITvInputSession.Stub implements Hand
                break;
            }
        }
        long duration = System.currentTimeMillis() - startTime;
        if (duration > EXECUTE_MESSAGE_TIMEOUT_SHORT_MILLIS) {
        long durationMs = (System.nanoTime() - startTime) / (1000 * 1000);
        if (durationMs > EXECUTE_MESSAGE_TIMEOUT_SHORT_MILLIS) {
            Log.w(TAG, "Handling message (" + msg.what + ") took too long time (duration="
                    + duration + "ms)");
            if (msg.what == DO_TUNE && duration > EXECUTE_MESSAGE_TUNE_TIMEOUT_MILLIS) {
                throw new RuntimeException("Too much time to handle tune request. (" + duration
                    + durationMs + "ms)");
            if (msg.what == DO_TUNE && durationMs > EXECUTE_MESSAGE_TUNE_TIMEOUT_MILLIS) {
                throw new RuntimeException("Too much time to handle tune request. (" + durationMs
                        + "ms > " + EXECUTE_MESSAGE_TUNE_TIMEOUT_MILLIS + "ms) "
                        + "Consider handling the tune request in a separate thread.");
            }
            if (duration > EXECUTE_MESSAGE_TIMEOUT_LONG_MILLIS) {
            if (durationMs > EXECUTE_MESSAGE_TIMEOUT_LONG_MILLIS) {
                throw new RuntimeException("Too much time to handle a request. (type=" + msg.what +
                        ", " + duration + "ms > " + EXECUTE_MESSAGE_TIMEOUT_LONG_MILLIS + "ms).");
                        ", " + durationMs + "ms > " + EXECUTE_MESSAGE_TIMEOUT_LONG_MILLIS + "ms).");
            }
        }
    }