Loading services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +3 −7 Original line number Diff line number Diff line Loading @@ -679,7 +679,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { // to decide whether an existing policy in the {@link #DEVICE_POLICIES_XML} needs to // be upgraded. See {@link PolicyVersionUpgrader} on instructions how to add an upgrade // step. static final int DPMS_VERSION = 5; static final int DPMS_VERSION = 6; static { SECURE_SETTINGS_ALLOWLIST = new ArraySet<>(); Loading Loading @@ -875,8 +875,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { private static final boolean DEFAULT_ENABLE_DEVICE_POLICY_ENGINE_FOR_FINANCE_FLAG = true; // TODO(b/265683382) remove the flag after rollout. private static final String KEEP_PROFILES_RUNNING_FLAG = "enable_keep_profiles_running"; public static final boolean DEFAULT_KEEP_PROFILES_RUNNING_FLAG = true; public static final boolean DEFAULT_KEEP_PROFILES_RUNNING_FLAG = false; // TODO(b/261999445) remove the flag after rollout. private static final String HEADLESS_FLAG = "headless"; Loading Loading @@ -23825,10 +23824,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { } private static boolean isKeepProfilesRunningFlagEnabled() { return DeviceConfig.getBoolean( NAMESPACE_DEVICE_POLICY_MANAGER, KEEP_PROFILES_RUNNING_FLAG, DEFAULT_KEEP_PROFILES_RUNNING_FLAG); return DEFAULT_KEEP_PROFILES_RUNNING_FLAG; } private boolean isUnicornFlagEnabled() { services/devicepolicy/java/com/android/server/devicepolicy/PolicyVersionUpgrader.java +17 −0 Original line number Diff line number Diff line Loading @@ -116,6 +116,19 @@ public class PolicyVersionUpgrader { currentVersion = 5; } if (currentVersion == 5) { Slog.i(LOG_TAG, String.format("Upgrading from version %d", currentVersion)); // No-op upgrade here: // DevicePolicyData.mEffectiveKeepProfilesRunning is only stored in XML file when it is // different from its default value, otherwise the tag is not written. When loading, if // the tag is missing, the field retains the value previously assigned in the // constructor, which is the default value. // In version 5 the default value was 'true', in version 6 it is 'false', so when // loading XML version 5 we need to initialize the field to 'true' for it to be restored // correctly in case the tag is missing. This is done in loadDataForUser(). currentVersion = 6; } writePoliciesAndVersion(allUsers, allUsersData, ownersData, currentVersion); } Loading Loading @@ -281,6 +294,10 @@ public class PolicyVersionUpgrader { private DevicePolicyData loadDataForUser( int userId, int loadVersion, ComponentName ownerComponent) { DevicePolicyData policy = new DevicePolicyData(userId); // See version 5 -> 6 step in upgradePolicy() if (loadVersion == 5 && userId == UserHandle.USER_SYSTEM) { policy.mEffectiveKeepProfilesRunning = true; } DevicePolicyData.load(policy, mProvider.makeDevicePoliciesJournaledFile(userId), mProvider.getAdminInfoSupplier(userId), Loading services/tests/servicestests/assets/PolicyVersionUpgraderTest/device_policies_keep_profiles_running_false.xml 0 → 100644 +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> services/tests/servicestests/assets/PolicyVersionUpgraderTest/device_policies_keep_profiles_running_true.xml 0 → 100644 +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> services/tests/servicestests/src/com/android/server/devicepolicy/PolicyVersionUpgraderTest.java +104 −3 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading @@ -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); Loading Loading
services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +3 −7 Original line number Diff line number Diff line Loading @@ -679,7 +679,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { // to decide whether an existing policy in the {@link #DEVICE_POLICIES_XML} needs to // be upgraded. See {@link PolicyVersionUpgrader} on instructions how to add an upgrade // step. static final int DPMS_VERSION = 5; static final int DPMS_VERSION = 6; static { SECURE_SETTINGS_ALLOWLIST = new ArraySet<>(); Loading Loading @@ -875,8 +875,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { private static final boolean DEFAULT_ENABLE_DEVICE_POLICY_ENGINE_FOR_FINANCE_FLAG = true; // TODO(b/265683382) remove the flag after rollout. private static final String KEEP_PROFILES_RUNNING_FLAG = "enable_keep_profiles_running"; public static final boolean DEFAULT_KEEP_PROFILES_RUNNING_FLAG = true; public static final boolean DEFAULT_KEEP_PROFILES_RUNNING_FLAG = false; // TODO(b/261999445) remove the flag after rollout. private static final String HEADLESS_FLAG = "headless"; Loading Loading @@ -23825,10 +23824,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { } private static boolean isKeepProfilesRunningFlagEnabled() { return DeviceConfig.getBoolean( NAMESPACE_DEVICE_POLICY_MANAGER, KEEP_PROFILES_RUNNING_FLAG, DEFAULT_KEEP_PROFILES_RUNNING_FLAG); return DEFAULT_KEEP_PROFILES_RUNNING_FLAG; } private boolean isUnicornFlagEnabled() {
services/devicepolicy/java/com/android/server/devicepolicy/PolicyVersionUpgrader.java +17 −0 Original line number Diff line number Diff line Loading @@ -116,6 +116,19 @@ public class PolicyVersionUpgrader { currentVersion = 5; } if (currentVersion == 5) { Slog.i(LOG_TAG, String.format("Upgrading from version %d", currentVersion)); // No-op upgrade here: // DevicePolicyData.mEffectiveKeepProfilesRunning is only stored in XML file when it is // different from its default value, otherwise the tag is not written. When loading, if // the tag is missing, the field retains the value previously assigned in the // constructor, which is the default value. // In version 5 the default value was 'true', in version 6 it is 'false', so when // loading XML version 5 we need to initialize the field to 'true' for it to be restored // correctly in case the tag is missing. This is done in loadDataForUser(). currentVersion = 6; } writePoliciesAndVersion(allUsers, allUsersData, ownersData, currentVersion); } Loading Loading @@ -281,6 +294,10 @@ public class PolicyVersionUpgrader { private DevicePolicyData loadDataForUser( int userId, int loadVersion, ComponentName ownerComponent) { DevicePolicyData policy = new DevicePolicyData(userId); // See version 5 -> 6 step in upgradePolicy() if (loadVersion == 5 && userId == UserHandle.USER_SYSTEM) { policy.mEffectiveKeepProfilesRunning = true; } DevicePolicyData.load(policy, mProvider.makeDevicePoliciesJournaledFile(userId), mProvider.getAdminInfoSupplier(userId), Loading
services/tests/servicestests/assets/PolicyVersionUpgraderTest/device_policies_keep_profiles_running_false.xml 0 → 100644 +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>
services/tests/servicestests/assets/PolicyVersionUpgraderTest/device_policies_keep_profiles_running_true.xml 0 → 100644 +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>
services/tests/servicestests/src/com/android/server/devicepolicy/PolicyVersionUpgraderTest.java +104 −3 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading @@ -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); Loading