diff options
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/app/admin/DevicePolicyManager.java | 53 | ||||
| -rw-r--r-- | core/java/android/app/admin/IDevicePolicyManager.aidl | 3 |
2 files changed, 56 insertions, 0 deletions
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java index 47fd87d446ff..b9c91ea720f3 100644 --- a/core/java/android/app/admin/DevicePolicyManager.java +++ b/core/java/android/app/admin/DevicePolicyManager.java @@ -5696,11 +5696,21 @@ public class DevicePolicyManager { * <p> * The calling device admin must be a device owner, or alternatively a profile owner from * Android 8.0 (API level 26) or higher. If it is not, a security exception will be thrown. + * <p> + * Staring from Android 11, this API switches to use + * {@link UserManager#DISALLOW_CONFIG_DATE_TIME} to enforce the auto time settings. Calling + * this API to enforce auto time will result in + * {@link UserManager#DISALLOW_CONFIG_DATE_TIME} being set, while calling this API to lift + * the requirement will result in {@link UserManager#DISALLOW_CONFIG_DATE_TIME} being cleared. * * @param admin Which {@link DeviceAdminReceiver} this request is associated with. * @param required Whether auto time is set required or not. * @throws SecurityException if {@code admin} is not a device owner. + * @deprecated From {@link android.os.Build.VERSION_CODES#R}. Use {@link #setAutoTime} + * to turn auto time on or off and use {@link UserManager#DISALLOW_CONFIG_DATE_TIME} + * to prevent the user from changing this setting. */ + @Deprecated public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) { throwIfParentInstance("setAutoTimeRequired"); if (mService != null) { @@ -5714,7 +5724,9 @@ public class DevicePolicyManager { /** * @return true if auto time is required. + * @deprecated From {@link android.os.Build.VERSION_CODES#R}. Use {@link #getAutoTime} */ + @Deprecated public boolean getAutoTimeRequired() { throwIfParentInstance("getAutoTimeRequired"); if (mService != null) { @@ -5728,6 +5740,47 @@ public class DevicePolicyManager { } /** + * Called by a device owner, a profile owner for the primary user or a profile + * owner of an organization-owned managed profile to turn auto time on and off. + * Callers are recommended to use {@link UserManager#DISALLOW_CONFIG_DATE_TIME} + * to prevent the user from changing this setting. + * <p> + * If user restriction {@link UserManager#DISALLOW_CONFIG_DATE_TIME} is used, + * no user will be able set the date and time. Instead, the network date + * and time will be used. + * + * @param admin Which {@link DeviceAdminReceiver} this request is associated with. + * @param enabled Whether time should be obtained automatically from the network or not. + * @throws SecurityException if caller is not a device owner, a profile owner for the + * primary user, or a profile owner of an organization-owned managed profile. + */ + public void setAutoTime(@NonNull ComponentName admin, boolean enabled) { + if (mService != null) { + try { + mService.setAutoTime(admin, enabled); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + } + + /** + * @return true if auto time is enabled on the device. + * @throws SecurityException if caller is not a device owner, a profile owner for the + * primary user, or a profile owner of an organization-owned managed profile. + */ + public boolean getAutoTime(@NonNull ComponentName admin) { + if (mService != null) { + try { + return mService.getAutoTime(admin); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + return false; + } + + /** * Called by a device owner to set whether all users created on the device should be ephemeral. * <p> * The system user is exempt from this policy - it is never ephemeral. diff --git a/core/java/android/app/admin/IDevicePolicyManager.aidl b/core/java/android/app/admin/IDevicePolicyManager.aidl index df4b55483be5..f55026c76906 100644 --- a/core/java/android/app/admin/IDevicePolicyManager.aidl +++ b/core/java/android/app/admin/IDevicePolicyManager.aidl @@ -295,6 +295,9 @@ interface IDevicePolicyManager { void setAutoTimeRequired(in ComponentName who, boolean required); boolean getAutoTimeRequired(); + void setAutoTime(in ComponentName who, boolean enabled); + boolean getAutoTime(in ComponentName who); + void setForceEphemeralUsers(in ComponentName who, boolean forceEpehemeralUsers); boolean getForceEphemeralUsers(in ComponentName who); |
