Allow the profile owner to enforce auto time.

Test: runtest -c com.android.server.devicepolicy.DevicePolicyManagerTest frameworks-services

Change-Id: I1cb04cce5d232fba668535dd391459a050d62dd7
This commit is contained in:
Jason Parks
2017-01-17 15:25:17 -06:00
parent 34f04ffa0b
commit 841cb0a37f
2 changed files with 21 additions and 8 deletions

View File

@ -3735,13 +3735,13 @@ public class DevicePolicyManager {
}
/**
* Called by a device owner to set whether auto time is required. If auto time is required the
* user cannot set the date and time, but has to use network date and time.
* Called by a device or profile owner to set whether auto time is required. If auto time is
* required, no user will be able set the date and time and network date and time will be used.
* <p>
* Note: if auto time is required the user can still manually set the time zone.
* <p>
* The calling device admin must be a device owner. If it is not, a security exception will be
* thrown.
* The calling device admin must be a device or profile owner. If it is not, a security
* exception will be thrown.
*
* @param admin Which {@link DeviceAdminReceiver} this request is associated with.
* @param required Whether auto time is set required or not.

View File

@ -5574,7 +5574,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
}
/**
* Set whether auto time is required by the specified admin (must be device owner).
* Set whether auto time is required by the specified admin (must be device or profile owner).
*/
@Override
public void setAutoTimeRequired(ComponentName who, boolean required) {
@ -5585,7 +5585,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
final int userHandle = UserHandle.getCallingUserId();
synchronized (this) {
ActiveAdmin admin = getActiveAdminForCallerLocked(who,
DeviceAdminInfo.USES_POLICY_DEVICE_OWNER);
DeviceAdminInfo.USES_POLICY_PROFILE_OWNER);
if (admin.requireAutoTime != required) {
admin.requireAutoTime = required;
saveSettingsLocked(userHandle);
@ -5604,7 +5604,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
}
/**
* Returns whether or not auto time is required by the device owner.
* Returns whether or not auto time is required by the device owner or any profile owner.
*/
@Override
public boolean getAutoTimeRequired() {
@ -5613,7 +5613,20 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
}
synchronized (this) {
ActiveAdmin deviceOwner = getDeviceOwnerAdminLocked();
return (deviceOwner != null) ? deviceOwner.requireAutoTime : false;
if (deviceOwner != null && deviceOwner.requireAutoTime) {
// If the device owner enforces auto time, we don't need to check the PO's
return true;
}
// Now check to see if any profile owner on any user enforces auto time
for (Integer userId : mOwners.getProfileOwnerKeys()) {
ActiveAdmin profileOwner = getProfileOwnerAdminLocked(userId);
if (profileOwner != null && profileOwner.requireAutoTime) {
return true;
}
}
return false;
}
}