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

Commit 9d6d90ff authored by Pavel Grafov's avatar Pavel Grafov Committed by Automerger Merge Worker
Browse files

Merge changes from topic "tow-2-rollback-no-flag" into udc-d1-dev am: fd60f60c

parents 66e3542e fd60f60c
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<policies setup-complete="true" provisioning-state="3">
    <keep-profiles-running value="false" />
    <admin name="com.android.frameworks.servicestests/com.android.server.devicepolicy.DummyDeviceAdmins$Admin1">
        <policies flags="991" />
        <strong-auth-unlock-timeout value="0" />
        <organization-color value="-16738680" />
        <active-password value="0" />
    </admin>
</policies>
+10 −0
Original line number Diff line number Diff line
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<policies setup-complete="true" provisioning-state="3">
    <keep-profiles-running value="true" />
    <admin name="com.android.frameworks.servicestests/com.android.server.devicepolicy.DummyDeviceAdmins$Admin1">
        <policies flags="991" />
        <strong-auth-unlock-timeout value="0" />
        <organization-color value="-16738680" />
        <active-password value="0" />
    </admin>
</policies>
+104 −3
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@ import javax.xml.parsers.DocumentBuilderFactory;
public class PolicyVersionUpgraderTest extends DpmTestBase {
    // NOTE: Only change this value if the corresponding CL also adds a test to test the upgrade
    // to the new version.
    private static final int LATEST_TESTED_VERSION = 5;
    private static final int LATEST_TESTED_VERSION = 6;
    public static final String PERMISSIONS_TAG = "admin-can-grant-sensors-permissions";
    public static final String DEVICE_OWNER_XML = "device_owner_2.xml";
    private ComponentName mFakeAdmin;
@@ -313,7 +313,7 @@ public class PolicyVersionUpgraderTest extends DpmTestBase {
    }

    @Test
    public void testEffectiveKeepProfilesRunningSet() throws Exception {
    public void testEffectiveKeepProfilesRunningSetToFalse4To5() throws Exception {
        writeVersionToXml(4);

        final int userId = UserHandle.USER_SYSTEM;
@@ -327,9 +327,110 @@ public class PolicyVersionUpgraderTest extends DpmTestBase {
        Document policies = readPolicies(userId);
        Element keepProfilesRunning = (Element) policies.getDocumentElement()
                .getElementsByTagName("keep-profiles-running").item(0);
        assertThat(keepProfilesRunning.getAttribute("value")).isEqualTo("false");

        // Default value (false) is not serialized.
        assertThat(keepProfilesRunning).isNull();
    }
    @Test
    public void testEffectiveKeepProfilesRunningIsToFalse4To6() throws Exception {
        writeVersionToXml(4);

        final int userId = UserHandle.USER_SYSTEM;
        mProvider.mUsers = new int[]{userId};
        preparePoliciesFile(userId, "device_policies.xml");

        mUpgrader.upgradePolicy(6);

        assertThat(readVersionFromXml()).isAtLeast(6);

        Document policies = readPolicies(userId);
        Element keepProfilesRunning = (Element) policies.getDocumentElement()
                .getElementsByTagName("keep-profiles-running").item(0);

        // Default value (false) is not serialized.
        assertThat(keepProfilesRunning).isNull();
    }

    /**
     * Verify correct behaviour when upgrading from Android 13
     */
    @Test
    public void testEffectiveKeepProfilesRunningIsToFalse3To6() throws Exception {
        writeVersionToXml(3);

        final int userId = UserHandle.USER_SYSTEM;
        mProvider.mUsers = new int[]{userId};
        preparePoliciesFile(userId, "device_policies.xml");

        mUpgrader.upgradePolicy(6);

        assertThat(readVersionFromXml()).isAtLeast(6);

        Document policies = readPolicies(userId);
        Element keepProfilesRunning = (Element) policies.getDocumentElement()
                .getElementsByTagName("keep-profiles-running").item(0);

        // Default value (false) is not serialized.
        assertThat(keepProfilesRunning).isNull();
    }

    @Test
    public void testEffectiveKeepProfilesRunningMissingInV5() throws Exception {
        writeVersionToXml(5);

        final int userId = UserHandle.USER_SYSTEM;
        mProvider.mUsers = new int[]{userId};
        preparePoliciesFile(userId, "device_policies.xml");

        mUpgrader.upgradePolicy(6);

        assertThat(readVersionFromXml()).isAtLeast(6);

        Document policies = readPolicies(userId);
        Element keepProfilesRunning = (Element) policies.getDocumentElement()
                .getElementsByTagName("keep-profiles-running").item(0);
        assertThat(keepProfilesRunning.getAttribute("value")).isEqualTo("true");
    }

    @Test
    public void testEffectiveKeepProfilesRunningTrueInV5() throws Exception {
        writeVersionToXml(5);

        final int userId = UserHandle.USER_SYSTEM;
        mProvider.mUsers = new int[]{userId};
        preparePoliciesFile(userId, "device_policies_keep_profiles_running_true.xml");

        mUpgrader.upgradePolicy(6);

        assertThat(readVersionFromXml()).isAtLeast(6);

        Document policies = readPolicies(userId);
        Element keepProfilesRunning = (Element) policies.getDocumentElement()
                .getElementsByTagName("keep-profiles-running").item(0);
        assertThat(keepProfilesRunning.getAttribute("value")).isEqualTo("true");
    }

    @Test
    public void testEffectiveKeepProfilesRunningFalseInV5() throws Exception {
        writeVersionToXml(5);

        final int userId = UserHandle.USER_SYSTEM;
        mProvider.mUsers = new int[]{userId};
        preparePoliciesFile(userId, "device_policies_keep_profiles_running_false.xml");

        mUpgrader.upgradePolicy(6);

        assertThat(readVersionFromXml()).isAtLeast(6);

        Document policies = readPolicies(userId);
        Element keepProfilesRunning = (Element) policies.getDocumentElement()
                .getElementsByTagName("keep-profiles-running").item(0);

        // Default value (false) is not serialized.
        assertThat(keepProfilesRunning).isNull();
    }


    @Test
    public void isLatestVersionTested() {
        assertThat(DevicePolicyManagerService.DPMS_VERSION).isEqualTo(LATEST_TESTED_VERSION);