summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Alex Johnston <acjohnston@google.com> 2020-03-03 10:42:26 +0000
committer Alex Johnston <acjohnston@google.com> 2020-04-09 11:57:49 +0100
commit9876c4f89915fcbd2828c22c75452587c69a208e (patch)
treede240a3bb9dc80c7d0964202fe70e76ec75da2f8
parente68c8ac02bb4bd3907c6513992f6f22c151e1a8e (diff)
Upgrade case for setAutoTimeRequired
* Modified setAutoTimeRequired to call pushUserRestrictions after requireAutoTime in the active admin is set. * Modified addSyntheticRestrictions in the active admin to include the auto time required case. Bug: 145604635 Test: atest com.android.server.devicepolicy.DevicePolicyManagerTest atest com.android.server.devicepolicy.DevicePolicyManagerServiceMigrationTest Change-Id: Ida4952eeec8ec12573c4049a9bf8e0ce6a951a86
-rw-r--r--services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java18
-rw-r--r--services/tests/servicestests/res/raw/comp_policies_primary.xml1
-rw-r--r--services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerServiceMigrationTest.java9
-rw-r--r--services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java18
4 files changed, 33 insertions, 13 deletions
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
index 67e83bad154f..d1d353dfbf39 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
@@ -1836,8 +1836,9 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
Bundle addSyntheticRestrictions(Bundle restrictions) {
if (disableCamera) {
restrictions.putBoolean(UserManager.DISALLOW_CAMERA, true);
- } else {
- restrictions.remove(UserManager.DISALLOW_CAMERA);
+ }
+ if (requireAutoTime) {
+ restrictions.putBoolean(UserManager.DISALLOW_CONFIG_DATE_TIME, true);
}
return restrictions;
}
@@ -1864,7 +1865,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
Bundle getEffectiveRestrictions() {
return addSyntheticRestrictions(
- removeDeprecatedRestrictions(ensureUserRestrictions()));
+ removeDeprecatedRestrictions(new Bundle(ensureUserRestrictions())));
}
Bundle getLocalUserRestrictions(int adminType) {
@@ -2747,6 +2748,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
// The following policies weren't available to PO, but will be available after migration.
parentAdmin.disableCamera = doAdmin.disableCamera;
+ parentAdmin.requireAutoTime = doAdmin.requireAutoTime;
+
// TODO(b/143516163): Uncomment once corresponding APIs are available via parent instance.
// parentAdmin.disableScreenCapture = doAdmin.disableScreenCapture;
// parentAdmin.accountTypesWithManagementDisabled.addAll(
@@ -7839,16 +7842,21 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
}
Objects.requireNonNull(who, "ComponentName is null");
final int userHandle = UserHandle.getCallingUserId();
+ boolean requireAutoTimeChanged = false;
synchronized (getLockObject()) {
ActiveAdmin admin = getActiveAdminForCallerLocked(who,
DeviceAdminInfo.USES_POLICY_PROFILE_OWNER);
if (admin.requireAutoTime != required) {
admin.requireAutoTime = required;
saveSettingsLocked(userHandle);
+ requireAutoTimeChanged = true;
}
}
-
- // TODO: (b/145604635) Add upgrade case
+ // requireAutoTime is now backed by DISALLOW_CONFIG_DATE_TIME restriction, so propagate
+ // updated restrictions to the framework.
+ if (requireAutoTimeChanged) {
+ pushUserRestrictions(userHandle);
+ }
// Turn AUTO_TIME on in settings if it is required
if (required) {
mInjector.binderWithCleanCallingIdentity(
diff --git a/services/tests/servicestests/res/raw/comp_policies_primary.xml b/services/tests/servicestests/res/raw/comp_policies_primary.xml
index d30f479195e3..8b7709e0a14f 100644
--- a/services/tests/servicestests/res/raw/comp_policies_primary.xml
+++ b/services/tests/servicestests/res/raw/comp_policies_primary.xml
@@ -3,6 +3,7 @@
<admin name="com.android.frameworks.servicestests/com.android.server.devicepolicy.DummyDeviceAdmins$Admin1">
<policies flags="991"/>
<password-history-length value="33" />
+ <require_auto_time value="true" />
<user-restrictions no_bluetooth="true" />
</admin>
</policies>
diff --git a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerServiceMigrationTest.java b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerServiceMigrationTest.java
index de2addffa2c5..c9bd01a31af0 100644
--- a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerServiceMigrationTest.java
+++ b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerServiceMigrationTest.java
@@ -385,6 +385,15 @@ public class DevicePolicyManagerServiceMigrationTest extends DpmTestBase {
assertFalse("User restriction was put into non-parent PO instance",
dpm.getUserRestrictions(admin1).containsKey(UserManager.DISALLOW_BLUETOOTH));
+ assertTrue("User restriction wasn't migrated to PO parent instance",
+ dpms.getProfileOwnerAdminLocked(COPE_PROFILE_USER_ID)
+ .getParentActiveAdmin()
+ .getEffectiveRestrictions()
+ .containsKey(UserManager.DISALLOW_CONFIG_DATE_TIME));
+ assertFalse("User restriction was put into non-parent PO instance",
+ dpms.getProfileOwnerAdminLocked(COPE_PROFILE_USER_ID)
+ .getEffectiveRestrictions()
+ .containsKey(UserManager.DISALLOW_CONFIG_DATE_TIME));
// TODO(b/143516163): verify more policies.
});
}
diff --git a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java
index d780370b9849..fe224ce058f4 100644
--- a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java
+++ b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java
@@ -2032,13 +2032,17 @@ public class DevicePolicyManagerTest extends DpmTestBase {
eq(false));
DpmTestUtils.assertRestrictions(
DpmTestUtils.newRestrictions(UserManager.DISALLOW_CAMERA),
- parentDpm.getUserRestrictions(admin1)
+ dpms.getProfileOwnerAdminLocked(DpmMockContext.CALLER_USER_HANDLE)
+ .getParentActiveAdmin()
+ .getEffectiveRestrictions()
);
parentDpm.setCameraDisabled(admin1, false);
DpmTestUtils.assertRestrictions(
DpmTestUtils.newRestrictions(),
- parentDpm.getUserRestrictions(admin1)
+ dpms.getProfileOwnerAdminLocked(DpmMockContext.CALLER_USER_HANDLE)
+ .getParentActiveAdmin()
+ .getEffectiveRestrictions()
);
reset(getServices().userManagerInternal);
}
@@ -2053,7 +2057,9 @@ public class DevicePolicyManagerTest extends DpmTestBase {
parentDpm.clearUserRestriction(admin1, restriction);
DpmTestUtils.assertRestrictions(
DpmTestUtils.newRestrictions(),
- parentDpm.getUserRestrictions(admin1)
+ dpms.getProfileOwnerAdminLocked(DpmMockContext.CALLER_USER_HANDLE)
+ .getParentActiveAdmin()
+ .getEffectiveRestrictions()
);
}
@@ -2088,11 +2094,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
private void assertNoDeviceOwnerRestrictions() {
DpmTestUtils.assertRestrictions(
DpmTestUtils.newRestrictions(),
- getDeviceOwner().ensureUserRestrictions()
- );
- DpmTestUtils.assertRestrictions(
- DpmTestUtils.newRestrictions(),
- dpm.getUserRestrictions(admin1)
+ getDeviceOwner().getEffectiveRestrictions()
);
}