From d469d2c83eec3fb622eb3521de86b37fca9a99a9 Mon Sep 17 00:00:00 2001 From: Jing Ji Date: Fri, 1 Apr 2022 17:58:58 -0700 Subject: [PATCH] Don't load app restriction from saved files in test As it interfers with testing. Bug: 203105544 Test: atest FrameworksMockingServicesTests:BackgroundRestrictionTest Change-Id: I6004f924c6e76fce1a9a20d2c26ddb9f4b960988 --- .../server/am/AppRestrictionController.java | 16 +++++++++++----- .../server/am/BackgroundRestrictionTest.java | 5 +++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/am/AppRestrictionController.java b/services/core/java/com/android/server/am/AppRestrictionController.java index c15deac701eb..a9e8aa1914b4 100644 --- a/services/core/java/com/android/server/am/AppRestrictionController.java +++ b/services/core/java/com/android/server/am/AppRestrictionController.java @@ -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() { diff --git a/services/tests/mockingservicestests/src/com/android/server/am/BackgroundRestrictionTest.java b/services/tests/mockingservicestests/src/com/android/server/am/BackgroundRestrictionTest.java index b512ac51e2fb..77cf54363c62 100644 --- a/services/tests/mockingservicestests/src/com/android/server/am/BackgroundRestrictionTest.java +++ b/services/tests/mockingservicestests/src/com/android/server/am/BackgroundRestrictionTest.java @@ -3056,6 +3056,11 @@ public final class BackgroundRestrictionTest { long currentTimeMillis() { return mCurrentTimeMillis; } + + @Override + boolean isTest() { + return true; + } } private class TestBaseTrackerInjector