Loading services/core/java/com/android/server/RescueParty.java +7 −0 Original line number Diff line number Diff line Loading @@ -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 Loading services/tests/mockingservicestests/src/com/android/server/RescuePartyTest.java +23 −0 Original line number Diff line number Diff line Loading @@ -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()); } Loading @@ -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()); } Loading Loading @@ -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()); } Loading Loading
services/core/java/com/android/server/RescueParty.java +7 −0 Original line number Diff line number Diff line Loading @@ -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 Loading
services/tests/mockingservicestests/src/com/android/server/RescuePartyTest.java +23 −0 Original line number Diff line number Diff line Loading @@ -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()); } Loading @@ -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()); } Loading Loading @@ -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()); } Loading