diff options
author | Harshit Mahajan <harshitmahajan@google.com> | 2024-04-24 16:14:30 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2024-04-24 16:14:30 +0000 |
commit | 25d36a491643c849e5ccfef3064544ca7769f586 (patch) | |
tree | 25549aeceef55b09aa8f983d468a91365daaeec5 | |
parent | dc21a0499726a3b9f6d11e1985538dbbae961e97 (diff) | |
parent | e1773b2e402887aac5650075f4aca585966fd491 (diff) | |
download | base-25d36a491643c849e5ccfef3064544ca7769f586.tar.gz |
Merge "Fixing RescuePartyTests" into main
-rw-r--r-- | services/core/java/com/android/server/RescueParty.java | 20 | ||||
-rw-r--r-- | services/tests/mockingservicestests/src/com/android/server/RescuePartyTest.java | 39 |
2 files changed, 41 insertions, 18 deletions
diff --git a/services/core/java/com/android/server/RescueParty.java b/services/core/java/com/android/server/RescueParty.java index 271d552fc574..37c2d263d14f 100644 --- a/services/core/java/com/android/server/RescueParty.java +++ b/services/core/java/com/android/server/RescueParty.java @@ -494,10 +494,10 @@ public class RescueParty { private static void executeRescueLevelInternalOld(Context context, int level, @Nullable String failedPackage) throws Exception { - if (level <= LEVEL_RESET_SETTINGS_TRUSTED_DEFAULTS) { - // Disabling flag resets on master branch for trunk stable launch. - // TODO(b/287618292): Re-enable them after the trunk stable is launched and we - // figured out a way to reset flags without interfering with trunk development. + // Note: DeviceConfig reset is disabled currently and would be enabled using the flag, + // after we have figured out a way to reset flags without interfering with trunk + // development. TODO: b/287618292 For enabling flag resets. + if (!Flags.allowRescuePartyFlagResets() && level <= LEVEL_RESET_SETTINGS_TRUSTED_DEFAULTS) { return; } @@ -572,12 +572,16 @@ public class RescueParty { level, levelToString(level)); switch (level) { case RESCUE_LEVEL_SCOPED_DEVICE_CONFIG_RESET: - // Temporary disable deviceConfig reset - // resetDeviceConfig(context, /*isScoped=*/true, failedPackage); + // Enable deviceConfig reset behind flag + if (Flags.allowRescuePartyFlagResets()) { + resetDeviceConfig(context, /*isScoped=*/true, failedPackage); + } break; case RESCUE_LEVEL_ALL_DEVICE_CONFIG_RESET: - // Temporary disable deviceConfig reset - // resetDeviceConfig(context, /*isScoped=*/false, failedPackage); + // Enable deviceConfig reset behind flag + if (Flags.allowRescuePartyFlagResets()) { + resetDeviceConfig(context, /*isScoped=*/false, failedPackage); + } break; case RESCUE_LEVEL_WARM_REBOOT: executeWarmReboot(context, level, failedPackage); diff --git a/services/tests/mockingservicestests/src/com/android/server/RescuePartyTest.java b/services/tests/mockingservicestests/src/com/android/server/RescuePartyTest.java index 697548cbe2b4..4a2164582890 100644 --- a/services/tests/mockingservicestests/src/com/android/server/RescuePartyTest.java +++ b/services/tests/mockingservicestests/src/com/android/server/RescuePartyTest.java @@ -25,6 +25,7 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.doAnswer; import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify; import static com.android.dx.mockito.inline.extended.ExtendedMockito.when; +import static com.android.server.RescueParty.DEFAULT_FACTORY_RESET_THROTTLE_DURATION_MIN; import static com.android.server.RescueParty.LEVEL_FACTORY_RESET; import static com.android.server.RescueParty.RESCUE_LEVEL_FACTORY_RESET; @@ -103,8 +104,6 @@ public class RescuePartyTest { private static final String PROP_DISABLE_FACTORY_RESET_FLAG = "persist.device_config.configuration.disable_rescue_party_factory_reset"; - private static final int THROTTLING_DURATION_MIN = 10; - @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); @@ -228,6 +227,9 @@ public class RescuePartyTest { setCrashRecoveryPropRescueBootCount(0); SystemProperties.set(RescueParty.PROP_ENABLE_RESCUE, Boolean.toString(true)); SystemProperties.set(PROP_DEVICE_CONFIG_DISABLE_FLAG, Boolean.toString(false)); + + // enable flag resets for tests + mSetFlagsRule.enableFlags(Flags.FLAG_ALLOW_RESCUE_PARTY_FLAG_RESETS); } @After @@ -312,6 +314,9 @@ public class RescuePartyTest { @Test public void testPersistentAppCrashDetectionWithExecutionForAllRescueLevels() { + // this is old test where the flag needs to be disabled + mSetFlagsRule.disableFlags(Flags.FLAG_RECOVERABILITY_DETECTION); + noteAppCrash(1, true); verifySettingsResets(Settings.RESET_MODE_UNTRUSTED_DEFAULTS, /*resetNamespaces=*/ null, @@ -378,6 +383,9 @@ public class RescuePartyTest { @Test public void testNonPersistentAppOnlyPerformsFlagResets() { + // this is old test where the flag needs to be disabled + mSetFlagsRule.disableFlags(Flags.FLAG_RECOVERABILITY_DETECTION); + noteAppCrash(1, false); verifySettingsResets(Settings.RESET_MODE_UNTRUSTED_DEFAULTS, /*resetNamespaces=*/ null, @@ -628,7 +636,8 @@ public class RescuePartyTest { public void testThrottlingOnBootFailures() { setCrashRecoveryPropAttemptingReboot(false); long now = System.currentTimeMillis(); - long beforeTimeout = now - TimeUnit.MINUTES.toMillis(THROTTLING_DURATION_MIN - 1); + long beforeTimeout = now - TimeUnit.MINUTES.toMillis( + DEFAULT_FACTORY_RESET_THROTTLE_DURATION_MIN - 1); setCrashRecoveryPropLastFactoryReset(beforeTimeout); for (int i = 1; i <= LEVEL_FACTORY_RESET; i++) { noteBoot(i); @@ -641,7 +650,8 @@ public class RescuePartyTest { mSetFlagsRule.enableFlags(Flags.FLAG_RECOVERABILITY_DETECTION); setCrashRecoveryPropAttemptingReboot(false); long now = System.currentTimeMillis(); - long beforeTimeout = now - TimeUnit.MINUTES.toMillis(THROTTLING_DURATION_MIN - 1); + long beforeTimeout = now - TimeUnit.MINUTES.toMillis( + DEFAULT_FACTORY_RESET_THROTTLE_DURATION_MIN - 1); setCrashRecoveryPropLastFactoryReset(beforeTimeout); for (int i = 1; i <= RESCUE_LEVEL_FACTORY_RESET; i++) { noteBoot(i); @@ -653,7 +663,8 @@ public class RescuePartyTest { public void testThrottlingOnAppCrash() { setCrashRecoveryPropAttemptingReboot(false); long now = System.currentTimeMillis(); - long beforeTimeout = now - TimeUnit.MINUTES.toMillis(THROTTLING_DURATION_MIN - 1); + long beforeTimeout = now - TimeUnit.MINUTES.toMillis( + DEFAULT_FACTORY_RESET_THROTTLE_DURATION_MIN - 1); setCrashRecoveryPropLastFactoryReset(beforeTimeout); for (int i = 0; i <= LEVEL_FACTORY_RESET; i++) { noteAppCrash(i + 1, true); @@ -666,7 +677,8 @@ public class RescuePartyTest { mSetFlagsRule.enableFlags(Flags.FLAG_RECOVERABILITY_DETECTION); setCrashRecoveryPropAttemptingReboot(false); long now = System.currentTimeMillis(); - long beforeTimeout = now - TimeUnit.MINUTES.toMillis(THROTTLING_DURATION_MIN - 1); + long beforeTimeout = now - TimeUnit.MINUTES.toMillis( + DEFAULT_FACTORY_RESET_THROTTLE_DURATION_MIN - 1); setCrashRecoveryPropLastFactoryReset(beforeTimeout); for (int i = 0; i <= RESCUE_LEVEL_FACTORY_RESET; i++) { noteAppCrash(i + 1, true); @@ -678,7 +690,8 @@ public class RescuePartyTest { public void testNotThrottlingAfterTimeoutOnBootFailures() { setCrashRecoveryPropAttemptingReboot(false); long now = System.currentTimeMillis(); - long afterTimeout = now - TimeUnit.MINUTES.toMillis(THROTTLING_DURATION_MIN + 1); + long afterTimeout = now - TimeUnit.MINUTES.toMillis( + DEFAULT_FACTORY_RESET_THROTTLE_DURATION_MIN + 1); setCrashRecoveryPropLastFactoryReset(afterTimeout); for (int i = 1; i <= LEVEL_FACTORY_RESET; i++) { noteBoot(i); @@ -691,7 +704,8 @@ public class RescuePartyTest { mSetFlagsRule.enableFlags(Flags.FLAG_RECOVERABILITY_DETECTION); setCrashRecoveryPropAttemptingReboot(false); long now = System.currentTimeMillis(); - long afterTimeout = now - TimeUnit.MINUTES.toMillis(THROTTLING_DURATION_MIN + 1); + long afterTimeout = now - TimeUnit.MINUTES.toMillis( + DEFAULT_FACTORY_RESET_THROTTLE_DURATION_MIN + 1); setCrashRecoveryPropLastFactoryReset(afterTimeout); for (int i = 1; i <= RESCUE_LEVEL_FACTORY_RESET; i++) { noteBoot(i); @@ -703,7 +717,8 @@ public class RescuePartyTest { public void testNotThrottlingAfterTimeoutOnAppCrash() { setCrashRecoveryPropAttemptingReboot(false); long now = System.currentTimeMillis(); - long afterTimeout = now - TimeUnit.MINUTES.toMillis(THROTTLING_DURATION_MIN + 1); + long afterTimeout = now - TimeUnit.MINUTES.toMillis( + DEFAULT_FACTORY_RESET_THROTTLE_DURATION_MIN + 1); setCrashRecoveryPropLastFactoryReset(afterTimeout); for (int i = 0; i <= LEVEL_FACTORY_RESET; i++) { noteAppCrash(i + 1, true); @@ -716,7 +731,8 @@ public class RescuePartyTest { mSetFlagsRule.enableFlags(Flags.FLAG_RECOVERABILITY_DETECTION); setCrashRecoveryPropAttemptingReboot(false); long now = System.currentTimeMillis(); - long afterTimeout = now - TimeUnit.MINUTES.toMillis(THROTTLING_DURATION_MIN + 1); + long afterTimeout = now - TimeUnit.MINUTES.toMillis( + DEFAULT_FACTORY_RESET_THROTTLE_DURATION_MIN + 1); setCrashRecoveryPropLastFactoryReset(afterTimeout); for (int i = 0; i <= RESCUE_LEVEL_FACTORY_RESET; i++) { noteAppCrash(i + 1, true); @@ -794,6 +810,9 @@ public class RescuePartyTest { @Test public void testHealthCheckLevels() { + // this is old test where the flag needs to be disabled + mSetFlagsRule.disableFlags(Flags.FLAG_RECOVERABILITY_DETECTION); + RescuePartyObserver observer = RescuePartyObserver.getInstance(mMockContext); // Ensure that no action is taken for cases where the failure reason is unknown |