Merge "Upgrade case for setAutoTimeRequired" into rvc-dev am: 0131d50188

Change-Id: I6ff133c8e5a56f1ab86a19a9baf0d000c74a96b3
This commit is contained in:
TreeHugger Robot
2020-04-09 13:09:29 +00:00
committed by Automerger Merge Worker
4 changed files with 33 additions and 13 deletions

View File

@@ -1836,8 +1836,9 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
Bundle addSyntheticRestrictions(Bundle restrictions) { Bundle addSyntheticRestrictions(Bundle restrictions) {
if (disableCamera) { if (disableCamera) {
restrictions.putBoolean(UserManager.DISALLOW_CAMERA, true); restrictions.putBoolean(UserManager.DISALLOW_CAMERA, true);
} else { }
restrictions.remove(UserManager.DISALLOW_CAMERA); if (requireAutoTime) {
restrictions.putBoolean(UserManager.DISALLOW_CONFIG_DATE_TIME, true);
} }
return restrictions; return restrictions;
} }
@@ -1864,7 +1865,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
Bundle getEffectiveRestrictions() { Bundle getEffectiveRestrictions() {
return addSyntheticRestrictions( return addSyntheticRestrictions(
removeDeprecatedRestrictions(ensureUserRestrictions())); removeDeprecatedRestrictions(new Bundle(ensureUserRestrictions())));
} }
Bundle getLocalUserRestrictions(int adminType) { 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. // The following policies weren't available to PO, but will be available after migration.
parentAdmin.disableCamera = doAdmin.disableCamera; parentAdmin.disableCamera = doAdmin.disableCamera;
parentAdmin.requireAutoTime = doAdmin.requireAutoTime;
// TODO(b/143516163): Uncomment once corresponding APIs are available via parent instance. // TODO(b/143516163): Uncomment once corresponding APIs are available via parent instance.
// parentAdmin.disableScreenCapture = doAdmin.disableScreenCapture; // parentAdmin.disableScreenCapture = doAdmin.disableScreenCapture;
// parentAdmin.accountTypesWithManagementDisabled.addAll( // parentAdmin.accountTypesWithManagementDisabled.addAll(
@@ -7839,16 +7842,21 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
} }
Objects.requireNonNull(who, "ComponentName is null"); Objects.requireNonNull(who, "ComponentName is null");
final int userHandle = UserHandle.getCallingUserId(); final int userHandle = UserHandle.getCallingUserId();
boolean requireAutoTimeChanged = false;
synchronized (getLockObject()) { synchronized (getLockObject()) {
ActiveAdmin admin = getActiveAdminForCallerLocked(who, ActiveAdmin admin = getActiveAdminForCallerLocked(who,
DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); DeviceAdminInfo.USES_POLICY_PROFILE_OWNER);
if (admin.requireAutoTime != required) { if (admin.requireAutoTime != required) {
admin.requireAutoTime = required; admin.requireAutoTime = required;
saveSettingsLocked(userHandle); saveSettingsLocked(userHandle);
requireAutoTimeChanged = true;
} }
} }
// requireAutoTime is now backed by DISALLOW_CONFIG_DATE_TIME restriction, so propagate
// TODO: (b/145604635) Add upgrade case // updated restrictions to the framework.
if (requireAutoTimeChanged) {
pushUserRestrictions(userHandle);
}
// Turn AUTO_TIME on in settings if it is required // Turn AUTO_TIME on in settings if it is required
if (required) { if (required) {
mInjector.binderWithCleanCallingIdentity( mInjector.binderWithCleanCallingIdentity(

View File

@@ -3,6 +3,7 @@
<admin name="com.android.frameworks.servicestests/com.android.server.devicepolicy.DummyDeviceAdmins$Admin1"> <admin name="com.android.frameworks.servicestests/com.android.server.devicepolicy.DummyDeviceAdmins$Admin1">
<policies flags="991"/> <policies flags="991"/>
<password-history-length value="33" /> <password-history-length value="33" />
<require_auto_time value="true" />
<user-restrictions no_bluetooth="true" /> <user-restrictions no_bluetooth="true" />
</admin> </admin>
</policies> </policies>

View File

@@ -385,6 +385,15 @@ public class DevicePolicyManagerServiceMigrationTest extends DpmTestBase {
assertFalse("User restriction was put into non-parent PO instance", assertFalse("User restriction was put into non-parent PO instance",
dpm.getUserRestrictions(admin1).containsKey(UserManager.DISALLOW_BLUETOOTH)); 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. // TODO(b/143516163): verify more policies.
}); });
} }

View File

@@ -2032,13 +2032,17 @@ public class DevicePolicyManagerTest extends DpmTestBase {
eq(false)); eq(false));
DpmTestUtils.assertRestrictions( DpmTestUtils.assertRestrictions(
DpmTestUtils.newRestrictions(UserManager.DISALLOW_CAMERA), DpmTestUtils.newRestrictions(UserManager.DISALLOW_CAMERA),
parentDpm.getUserRestrictions(admin1) dpms.getProfileOwnerAdminLocked(DpmMockContext.CALLER_USER_HANDLE)
.getParentActiveAdmin()
.getEffectiveRestrictions()
); );
parentDpm.setCameraDisabled(admin1, false); parentDpm.setCameraDisabled(admin1, false);
DpmTestUtils.assertRestrictions( DpmTestUtils.assertRestrictions(
DpmTestUtils.newRestrictions(), DpmTestUtils.newRestrictions(),
parentDpm.getUserRestrictions(admin1) dpms.getProfileOwnerAdminLocked(DpmMockContext.CALLER_USER_HANDLE)
.getParentActiveAdmin()
.getEffectiveRestrictions()
); );
reset(getServices().userManagerInternal); reset(getServices().userManagerInternal);
} }
@@ -2053,7 +2057,9 @@ public class DevicePolicyManagerTest extends DpmTestBase {
parentDpm.clearUserRestriction(admin1, restriction); parentDpm.clearUserRestriction(admin1, restriction);
DpmTestUtils.assertRestrictions( DpmTestUtils.assertRestrictions(
DpmTestUtils.newRestrictions(), 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() { private void assertNoDeviceOwnerRestrictions() {
DpmTestUtils.assertRestrictions( DpmTestUtils.assertRestrictions(
DpmTestUtils.newRestrictions(), DpmTestUtils.newRestrictions(),
getDeviceOwner().ensureUserRestrictions() getDeviceOwner().getEffectiveRestrictions()
);
DpmTestUtils.assertRestrictions(
DpmTestUtils.newRestrictions(),
dpm.getUserRestrictions(admin1)
); );
} }