Merge "AppIdleHistory: Only write screen on durations during regular sync" into nyc-mr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
1af694510d
@@ -67,7 +67,7 @@ public class AppIdleHistoryTests extends AndroidTestCase {
|
|||||||
// Screen on time should not keep progressing with screen is off
|
// Screen on time should not keep progressing with screen is off
|
||||||
assertEquals(aih.getScreenOnTimeLocked(7000), 3000);
|
assertEquals(aih.getScreenOnTimeLocked(7000), 3000);
|
||||||
assertEquals(aih.getScreenOnTimeLocked(8000), 3000);
|
assertEquals(aih.getScreenOnTimeLocked(8000), 3000);
|
||||||
aih.writeElapsedTimeLocked();
|
aih.writeAppIdleDurationsLocked();
|
||||||
|
|
||||||
// Check if the screen on time is persisted across instantiations
|
// Check if the screen on time is persisted across instantiations
|
||||||
AppIdleHistory aih2 = new AppIdleHistory(mStorageDir, 0);
|
AppIdleHistory aih2 = new AppIdleHistory(mStorageDir, 0);
|
||||||
|
|||||||
@@ -118,7 +118,6 @@ public class AppIdleHistory {
|
|||||||
} else {
|
} else {
|
||||||
mScreenOnDuration += elapsedRealtime - mScreenOnSnapshot;
|
mScreenOnDuration += elapsedRealtime - mScreenOnSnapshot;
|
||||||
mElapsedDuration += elapsedRealtime - mElapsedSnapshot;
|
mElapsedDuration += elapsedRealtime - mElapsedSnapshot;
|
||||||
writeScreenOnTimeLocked();
|
|
||||||
mElapsedSnapshot = elapsedRealtime;
|
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
|
* 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();
|
final long elapsedRealtime = SystemClock.elapsedRealtime();
|
||||||
// Only bump up and snapshot the elapsed time. Don't change screen on duration.
|
// Only bump up and snapshot the elapsed time. Don't change screen on duration.
|
||||||
mElapsedDuration += elapsedRealtime - mElapsedSnapshot;
|
mElapsedDuration += elapsedRealtime - mElapsedSnapshot;
|
||||||
|
|||||||
@@ -304,9 +304,9 @@ public class UsageStatsService extends SystemService implements
|
|||||||
|
|
||||||
@Override public void onDisplayChanged(int displayId) {
|
@Override public void onDisplayChanged(int displayId) {
|
||||||
if (displayId == Display.DEFAULT_DISPLAY) {
|
if (displayId == Display.DEFAULT_DISPLAY) {
|
||||||
|
final boolean displayOn = isDisplayOn();
|
||||||
synchronized (UsageStatsService.this.mLock) {
|
synchronized (UsageStatsService.this.mLock) {
|
||||||
mAppIdleHistory.updateDisplayLocked(isDisplayOn(),
|
mAppIdleHistory.updateDisplayLocked(displayOn, SystemClock.elapsedRealtime());
|
||||||
SystemClock.elapsedRealtime());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1005,9 +1005,9 @@ public class UsageStatsService extends SystemService implements
|
|||||||
service.persistActiveStats();
|
service.persistActiveStats();
|
||||||
mAppIdleHistory.writeAppIdleTimesLocked(mUserState.keyAt(i));
|
mAppIdleHistory.writeAppIdleTimesLocked(mUserState.keyAt(i));
|
||||||
}
|
}
|
||||||
// Persist elapsed time periodically, in case screen doesn't get toggled
|
// Persist elapsed and screen on time. If this fails for whatever reason, the apps will be
|
||||||
// until the next boot
|
// considered not-idle, which is the safest outcome in such an event.
|
||||||
mAppIdleHistory.writeElapsedTimeLocked();
|
mAppIdleHistory.writeAppIdleDurationsLocked();
|
||||||
mHandler.removeMessages(MSG_FLUSH_TO_DISK);
|
mHandler.removeMessages(MSG_FLUSH_TO_DISK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user