Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e1773b2e authored by Harshit Mahajan's avatar Harshit Mahajan
Browse files

Fixing RescuePartyTests

1. Enabling "flag resets" behind aconfig flag
2. Mocking the above flag in Tests

Bug: 333720513
Test: atest RescuePartyTest
Change-Id: I87e82def65b01367dbb36c7324b91c36203f2409
parent 067e0eb8
Loading
Loading
Loading
Loading
+12 −8
Original line number Diff line number Diff line
@@ -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);
+29 −10
Original line number Diff line number Diff line
@@ -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