Initialize the app last used timestamps to 0 in test setup.

These tests are currently assuming the initial last used
timestamps to be 0 which is used to be true but not anymore
after the change Ib90b435b1efc34144f0461aaaf339fc6037ecdc2.
So, explicitly initialize the last used timestamps to 0
in the test setup to keep these tests working.

Bug: 225776572
Test: atest services/tests/servicestests/src/com/android/server/usage/AppStandbyControllerTests.java
Change-Id: I5a0246d1d9fec57bd37b941eb93701dfc7da7576
This commit is contained in:
Sudheer Shanka
2022-03-22 19:48:36 -07:00
parent be8f4d0cd0
commit e32a0c26c0
2 changed files with 32 additions and 2 deletions

View File

@@ -2096,6 +2096,13 @@ public class AppStandbyController
.sendToTarget();
}
@VisibleForTesting
AppIdleHistory getAppIdleHistoryForTest() {
synchronized (mAppIdleLock) {
return mAppIdleHistory;
}
}
@Override
public void dumpUsers(IndentingPrintWriter idpw, int[] userIds, List<String> pkgs) {
synchronized (mAppIdleLock) {

View File

@@ -512,8 +512,30 @@ public class AppStandbyControllerTests {
return controller;
}
private long getCurrentTime() {
return TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
private void setupInitialUsageHistory() throws Exception {
final int[] userIds = new int[] { USER_ID, USER_ID2, USER_ID3 };
final String[] packages = new String[] {
PACKAGE_1,
PACKAGE_2,
PACKAGE_EXEMPTED_1,
PACKAGE_SYSTEM_HEADFULL,
PACKAGE_SYSTEM_HEADLESS,
PACKAGE_WELLBEING,
PACKAGE_BACKGROUND_LOCATION,
ADMIN_PKG,
ADMIN_PKG2,
ADMIN_PKG3
};
for (int userId : userIds) {
for (String pkg : packages) {
final AppIdleHistory.AppUsageHistory usageHistory = mController
.getAppIdleHistoryForTest().getAppUsageHistory(
pkg, userId, mInjector.mElapsedRealtime);
usageHistory.lastUsedElapsedTime = 0;
usageHistory.lastUsedByUserElapsedTime = 0;
usageHistory.lastUsedScreenTime = 0;
}
}
}
@Before
@@ -524,6 +546,7 @@ public class AppStandbyControllerTests {
MyContextWrapper myContext = new MyContextWrapper(InstrumentationRegistry.getContext());
mInjector = new MyInjector(myContext, Looper.getMainLooper());
mController = setupController();
setupInitialUsageHistory();
}
@After