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

Commit e70b5421 authored by Adam Lesinski's avatar Adam Lesinski Committed by android-build-merger
Browse files

AppIdleHistory: Only write screen on durations during regular sync am: f2d87eba am: a6109265

am: 05f023dc

Change-Id: Ie3c9299f999e9c8bb7200606589f796598c64b55
parents c200c58e 05f023dc
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@ public class AppIdleHistoryTests extends AndroidTestCase {
        // Screen on time should not keep progressing with screen is off
        assertEquals(aih.getScreenOnTimeLocked(7000), 3000);
        assertEquals(aih.getScreenOnTimeLocked(8000), 3000);
        aih.writeElapsedTimeLocked();
        aih.writeAppIdleDurationsLocked();

        // Check if the screen on time is persisted across instantiations
        AppIdleHistory aih2 = new AppIdleHistory(mStorageDir, 0);
+1 −2
Original line number Diff line number Diff line
@@ -118,7 +118,6 @@ public class AppIdleHistory {
        } else {
            mScreenOnDuration += elapsedRealtime - mScreenOnSnapshot;
            mElapsedDuration += elapsedRealtime - mElapsedSnapshot;
            writeScreenOnTimeLocked();
            mElapsedSnapshot = elapsedRealtime;
        }
    }
@@ -167,7 +166,7 @@ public class AppIdleHistory {
    /**
     * To be called periodically to keep track of elapsed time when app idle times are written
     */
    public void writeElapsedTimeLocked() {
    public void writeAppIdleDurationsLocked() {
        final long elapsedRealtime = SystemClock.elapsedRealtime();
        // Only bump up and snapshot the elapsed time. Don't change screen on duration.
        mElapsedDuration += elapsedRealtime - mElapsedSnapshot;
+5 −5
Original line number Diff line number Diff line
@@ -304,9 +304,9 @@ public class UsageStatsService extends SystemService implements

        @Override public void onDisplayChanged(int displayId) {
            if (displayId == Display.DEFAULT_DISPLAY) {
                final boolean displayOn = isDisplayOn();
                synchronized (UsageStatsService.this.mLock) {
                    mAppIdleHistory.updateDisplayLocked(isDisplayOn(),
                            SystemClock.elapsedRealtime());
                    mAppIdleHistory.updateDisplayLocked(displayOn, SystemClock.elapsedRealtime());
                }
            }
        }
@@ -1005,9 +1005,9 @@ public class UsageStatsService extends SystemService implements
            service.persistActiveStats();
            mAppIdleHistory.writeAppIdleTimesLocked(mUserState.keyAt(i));
        }
        // Persist elapsed time periodically, in case screen doesn't get toggled
        // until the next boot
        mAppIdleHistory.writeElapsedTimeLocked();
        // Persist elapsed and screen on time. If this fails for whatever reason, the apps will be
        // considered not-idle, which is the safest outcome in such an event.
        mAppIdleHistory.writeAppIdleDurationsLocked();
        mHandler.removeMessages(MSG_FLUSH_TO_DISK);
    }