Merge "Add logic to start FACTORY_RESET only after REBOOT completed"

This commit is contained in:
TreeHugger Robot
2022-12-01 00:50:23 +00:00
committed by Android (Google) Code Review
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());
}