Don't load app restriction from saved files in test

As it interfers with testing.

Bug: 203105544
Test: atest FrameworksMockingServicesTests:BackgroundRestrictionTest
Change-Id: I6004f924c6e76fce1a9a20d2c26ddb9f4b960988
This commit is contained in:
Jing Ji 2022-04-01 17:58:58 -07:00
parent 4935cbc65a
commit d469d2c83e
2 changed files with 16 additions and 5 deletions

View File

@ -1413,11 +1413,13 @@ public final class AppRestrictionController {
refreshAppRestrictionLevelForUser(userId, REASON_MAIN_FORCED_BY_USER,
REASON_SUB_FORCED_USER_FLAG_INTERACTION);
}
// Load the previously saved levels and update the current levels if needed.
mRestrictionSettings.scheduleLoadFromXml();
// Also save the current levels right away.
for (int userId : allUsers) {
mRestrictionSettings.schedulePersistToXml(userId);
if (!mInjector.isTest()) {
// Load the previously saved levels and update the current levels if needed.
mRestrictionSettings.scheduleLoadFromXml();
// Also save the current levels right away.
for (int userId : allUsers) {
mRestrictionSettings.schedulePersistToXml(userId);
}
}
}
@ -2822,6 +2824,10 @@ public final class AppRestrictionController {
@CurrentTimeMillisLong long currentTimeMillis() {
return System.currentTimeMillis();
}
boolean isTest() {
return false;
}
}
private void registerForSystemBroadcasts() {

View File

@ -3056,6 +3056,11 @@ public final class BackgroundRestrictionTest {
long currentTimeMillis() {
return mCurrentTimeMillis;
}
@Override
boolean isTest() {
return true;
}
}
private class TestBaseTrackerInjector<T extends BaseAppStatePolicy>