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

Commit 9acc4f40 authored by Daniel Nishi's avatar Daniel Nishi
Browse files

Add a debug flag to disable time correction.

This allows manual QA folks to change the datetime to test events
which depend on a large gap between uses of an app.

Currently, if the system detects a drift of more than 2 seconds,
it will automatically correct the usage stats. This means that manual
time changes will cause the usage stats to update to match, making it
impossible to test manually.

Bug: 34400961
Test: Manual
Change-Id: Iffb92c929872d841d22f089ec71922bf120cc544
parent 90f096f4
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ import android.os.Process;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
@@ -96,6 +97,8 @@ public class UsageStatsService extends SystemService implements
        UserUsageStatsService.StatsUpdatedListener {

    static final String TAG = "UsageStatsService";
    public static final boolean ENABLE_TIME_CHANGE_CORRECTION
            = SystemProperties.getBoolean("debug.time_change_correction", true);

    static final boolean DEBUG = false; // Never submit with true
    static final boolean COMPRESS_TIME = false;
@@ -639,7 +642,8 @@ public class UsageStatsService extends SystemService implements
        final long actualRealtime = SystemClock.elapsedRealtime();
        final long expectedSystemTime = (actualRealtime - mRealTimeSnapshot) + mSystemTimeSnapshot;
        final long diffSystemTime = actualSystemTime - expectedSystemTime;
        if (Math.abs(diffSystemTime) > TIME_CHANGE_THRESHOLD_MILLIS) {
        if (Math.abs(diffSystemTime) > TIME_CHANGE_THRESHOLD_MILLIS
                && ENABLE_TIME_CHANGE_CORRECTION) {
            // The time has changed.
            Slog.i(TAG, "Time changed in UsageStats by " + (diffSystemTime / 1000) + " seconds");
            final int userCount = mUserState.size();