Add logic to start FACTORY_RESET only after REBOOT completed

In case a package crashes very frequently, the escalation level 5 triggers before the level 4 is finished in RescueParty.
Hence the device could get FACTORY_RESET even before we try WARM_REBOOT
for rescue. Using the system property PROP_ATTEMPTING_REBOOT ensuring that factory reset level is executed only after reboot has taken place.

Bug: b/257269267
Test: atest RescuePartyTest

Change-Id: I64dfd0d93d5b17fcfe3cf1cb110e27e926b1052d
This commit is contained in:
Harshit Mahajan
2022-11-14 07:33:43 +00:00
parent 1f74ea0d35
commit 80ea048bc6
2 changed files with 30 additions and 0 deletions

View File

@@ -447,6 +447,13 @@ public class RescueParty {
thread.start();
break;
case LEVEL_FACTORY_RESET:
// Before the completion of Reboot, if any crash happens then PackageWatchdog
// escalates to next level i.e. factory reset, as they happen in separate threads.
// Adding a check to prevent factory reset to execute before above reboot completes.
// Note: this reboot property is not persistent resets after reboot is completed.
if (isRebootPropertySet()) {
break;
}
SystemProperties.set(PROP_ATTEMPTING_FACTORY_RESET, "true");
runnable = new Runnable() {
@Override

View File

@@ -252,6 +252,7 @@ public class RescuePartyTest {
noteBoot(4);
assertTrue(RescueParty.isRebootPropertySet());
SystemProperties.set(RescueParty.PROP_ATTEMPTING_REBOOT, Boolean.toString(false));
noteBoot(5);
assertTrue(RescueParty.isFactoryResetPropertySet());
}
@@ -276,6 +277,7 @@ public class RescuePartyTest {
noteAppCrash(4, true);
assertTrue(RescueParty.isRebootPropertySet());
SystemProperties.set(RescueParty.PROP_ATTEMPTING_REBOOT, Boolean.toString(false));
noteAppCrash(5, true);
assertTrue(RescueParty.isFactoryResetPropertySet());
}
@@ -429,6 +431,27 @@ public class RescuePartyTest {
for (int i = 0; i < LEVEL_FACTORY_RESET; i++) {
noteBoot(i + 1);
}
assertFalse(RescueParty.isFactoryResetPropertySet());
SystemProperties.set(RescueParty.PROP_ATTEMPTING_REBOOT, Boolean.toString(false));
noteBoot(LEVEL_FACTORY_RESET + 1);
assertTrue(RescueParty.isAttemptingFactoryReset());
assertTrue(RescueParty.isFactoryResetPropertySet());
}
@Test
public void testIsAttemptingFactoryResetOnlyAfterRebootCompleted() {
for (int i = 0; i < LEVEL_FACTORY_RESET; i++) {
noteBoot(i + 1);
}
int mitigationCount = LEVEL_FACTORY_RESET + 1;
assertFalse(RescueParty.isFactoryResetPropertySet());
noteBoot(mitigationCount++);
assertFalse(RescueParty.isFactoryResetPropertySet());
noteBoot(mitigationCount++);
assertFalse(RescueParty.isFactoryResetPropertySet());
noteBoot(mitigationCount++);
SystemProperties.set(RescueParty.PROP_ATTEMPTING_REBOOT, Boolean.toString(false));
noteBoot(mitigationCount + 1);
assertTrue(RescueParty.isAttemptingFactoryReset());
assertTrue(RescueParty.isFactoryResetPropertySet());
}