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

Commit 1815a532 authored by Hongyi Zhang's avatar Hongyi Zhang Committed by Automerger Merge Worker
Browse files

Merge "Fix RescueParty querying DeviceConfig before SettingsProvider ready"...

Merge "Fix RescueParty querying DeviceConfig before SettingsProvider ready" into rvc-dev am: c1081ff1 am: 7054b68d

Change-Id: I3f6c7f9901131faff8a3c2a6ad419407c3ce30e5
parents 67e57eab 7054b68d
Loading
Loading
Loading
Loading
+3 −4
Original line number Original line Diff line number Diff line
@@ -98,8 +98,8 @@ public class RescueParty {


    private static final String PROP_DISABLE_RESCUE = "persist.sys.disable_rescue";
    private static final String PROP_DISABLE_RESCUE = "persist.sys.disable_rescue";
    private static final String PROP_VIRTUAL_DEVICE = "ro.hardware.virtual_device";
    private static final String PROP_VIRTUAL_DEVICE = "ro.hardware.virtual_device";

    private static final String PROP_DEVICE_CONFIG_DISABLE_FLAG =
    private static final String DEVICE_CONFIG_DISABLE_FLAG = "disable_rescue_party";
            "persist.device_config.configuration.disable_rescue_party";


    private static final int PERSISTENT_MASK = ApplicationInfo.FLAG_PERSISTENT
    private static final int PERSISTENT_MASK = ApplicationInfo.FLAG_PERSISTENT
            | ApplicationInfo.FLAG_SYSTEM;
            | ApplicationInfo.FLAG_SYSTEM;
@@ -118,8 +118,7 @@ public class RescueParty {


        // We're disabled if the DeviceConfig disable flag is set to true.
        // We're disabled if the DeviceConfig disable flag is set to true.
        // This is in case that an emergency rollback of the feature is needed.
        // This is in case that an emergency rollback of the feature is needed.
        if (DeviceConfig.getBoolean(
        if (SystemProperties.getBoolean(PROP_DEVICE_CONFIG_DISABLE_FLAG, false)) {
                DeviceConfig.NAMESPACE_CONFIGURATION, DEVICE_CONFIG_DISABLE_FLAG, false)) {
            Slog.v(TAG, "Disabled because of DeviceConfig flag");
            Slog.v(TAG, "Disabled because of DeviceConfig flag");
            return true;
            return true;
        }
        }
+5 −13
Original line number Original line Diff line number Diff line
@@ -79,7 +79,8 @@ public class RescuePartyTest {
    private static final String CALLING_PACKAGE2 = "com.package.name2";
    private static final String CALLING_PACKAGE2 = "com.package.name2";
    private static final String NAMESPACE1 = "namespace1";
    private static final String NAMESPACE1 = "namespace1";
    private static final String NAMESPACE2 = "namespace2";
    private static final String NAMESPACE2 = "namespace2";
    private static final String DISABLE_RESCUE_PARTY_FLAG = "disable_rescue_party";
    private static final String PROP_DEVICE_CONFIG_DISABLE_FLAG =
            "persist.device_config.configuration.disable_rescue_party";


    private MockitoSession mSession;
    private MockitoSession mSession;
    private HashMap<String, String> mSystemSettingsMap;
    private HashMap<String, String> mSystemSettingsMap;
@@ -172,6 +173,7 @@ public class RescuePartyTest {
                Integer.toString(RescueParty.LEVEL_NONE));
                Integer.toString(RescueParty.LEVEL_NONE));
        SystemProperties.set(RescueParty.PROP_RESCUE_BOOT_COUNT, Integer.toString(0));
        SystemProperties.set(RescueParty.PROP_RESCUE_BOOT_COUNT, Integer.toString(0));
        SystemProperties.set(RescueParty.PROP_ENABLE_RESCUE, Boolean.toString(true));
        SystemProperties.set(RescueParty.PROP_ENABLE_RESCUE, Boolean.toString(true));
        SystemProperties.set(PROP_DEVICE_CONFIG_DISABLE_FLAG, Boolean.toString(false));
    }
    }


    @After
    @After
@@ -317,13 +319,6 @@ public class RescuePartyTest {


    @Test
    @Test
    public void testExplicitlyEnablingAndDisablingRescue() {
    public void testExplicitlyEnablingAndDisablingRescue() {
        // mock the DeviceConfig get call to avoid hitting
        // android.permission.READ_DEVICE_CONFIG when calling real DeviceConfig.
        doReturn(true)
                .when(() -> DeviceConfig.getBoolean(
                    eq(DeviceConfig.NAMESPACE_CONFIGURATION),
                    eq(DISABLE_RESCUE_PARTY_FLAG),
                    eq(false)));
        SystemProperties.set(RescueParty.PROP_ENABLE_RESCUE, Boolean.toString(false));
        SystemProperties.set(RescueParty.PROP_ENABLE_RESCUE, Boolean.toString(false));
        SystemProperties.set(PROP_DISABLE_RESCUE, Boolean.toString(true));
        SystemProperties.set(PROP_DISABLE_RESCUE, Boolean.toString(true));
        assertEquals(RescuePartyObserver.getInstance(mMockContext).execute(sFailingPackage,
        assertEquals(RescuePartyObserver.getInstance(mMockContext).execute(sFailingPackage,
@@ -336,18 +331,15 @@ public class RescuePartyTest {


    @Test
    @Test
    public void testDisablingRescueByDeviceConfigFlag() {
    public void testDisablingRescueByDeviceConfigFlag() {
        doReturn(true)
                .when(() -> DeviceConfig.getBoolean(
                    eq(DeviceConfig.NAMESPACE_CONFIGURATION),
                    eq(DISABLE_RESCUE_PARTY_FLAG),
                    eq(false)));
        SystemProperties.set(RescueParty.PROP_ENABLE_RESCUE, Boolean.toString(false));
        SystemProperties.set(RescueParty.PROP_ENABLE_RESCUE, Boolean.toString(false));
        SystemProperties.set(PROP_DEVICE_CONFIG_DISABLE_FLAG, Boolean.toString(true));


        assertEquals(RescuePartyObserver.getInstance(mMockContext).execute(sFailingPackage,
        assertEquals(RescuePartyObserver.getInstance(mMockContext).execute(sFailingPackage,
                PackageWatchdog.FAILURE_REASON_APP_NOT_RESPONDING), false);
                PackageWatchdog.FAILURE_REASON_APP_NOT_RESPONDING), false);


        // Restore the property value initalized in SetUp()
        // Restore the property value initalized in SetUp()
        SystemProperties.set(RescueParty.PROP_ENABLE_RESCUE, Boolean.toString(true));
        SystemProperties.set(RescueParty.PROP_ENABLE_RESCUE, Boolean.toString(true));
        SystemProperties.set(PROP_DEVICE_CONFIG_DISABLE_FLAG, Boolean.toString(false));
    }
    }


    @Test
    @Test