Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8c50338c authored by Alex Johnston's avatar Alex Johnston
Browse files

Replace setAutoTimeRequired and getAutoTimeRequired with setAutoTime and getAutoTime

* Deprecate setAutoTimeRequired and getAutoTimeRequired.
* Added new API methods setAutoTime and getAutoTime.
* DPCs are recommended to combine these new APIs together with the DISALLOW_CONFIG_DATE_TIME
  restriction to prevent the user from changing auto time settings.
* The new methods can also be called by the WP PO (COPE mode).

Bug: 138709470
Test: Manual testing with testdpc and the set auto time toggle
      atest com.android.server.devicepolicy.DevicePolicyManagerTest
      atest com.android.cts.devicepolicy.MixedProfileOwnerTest#testSetAutoTime

Change-Id: I6f93b2a28e3ef0e1e97c9c414ce65d4e753c1bf3
parent ee7d195f
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -6726,7 +6726,8 @@ package android.app.admin {
    method @Nullable public String getAlwaysOnVpnPackage(@NonNull android.content.ComponentName);
    method @NonNull @WorkerThread public android.os.Bundle getApplicationRestrictions(@Nullable android.content.ComponentName, String);
    method @Deprecated @Nullable public String getApplicationRestrictionsManagingPackage(@NonNull android.content.ComponentName);
    method public boolean getAutoTimeRequired();
    method public boolean getAutoTime(@NonNull android.content.ComponentName);
    method @Deprecated public boolean getAutoTimeRequired();
    method @NonNull public java.util.List<android.os.UserHandle> getBindDeviceAdminTargetUsers(@NonNull android.content.ComponentName);
    method public boolean getBluetoothContactSharingDisabled(@NonNull android.content.ComponentName);
    method public boolean getCameraDisabled(@Nullable android.content.ComponentName);
@@ -6842,7 +6843,8 @@ package android.app.admin {
    method public boolean setApplicationHidden(@NonNull android.content.ComponentName, String, boolean);
    method @WorkerThread public void setApplicationRestrictions(@Nullable android.content.ComponentName, String, android.os.Bundle);
    method @Deprecated public void setApplicationRestrictionsManagingPackage(@NonNull android.content.ComponentName, @Nullable String) throws android.content.pm.PackageManager.NameNotFoundException;
    method public void setAutoTimeRequired(@NonNull android.content.ComponentName, boolean);
    method public void setAutoTime(@NonNull android.content.ComponentName, boolean);
    method @Deprecated public void setAutoTimeRequired(@NonNull android.content.ComponentName, boolean);
    method public void setBackupServiceEnabled(@NonNull android.content.ComponentName, boolean);
    method public void setBluetoothContactSharingDisabled(@NonNull android.content.ComponentName, boolean);
    method public void setCameraDisabled(@NonNull android.content.ComponentName, boolean);
+53 −0
Original line number Diff line number Diff line
@@ -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) {
@@ -5727,6 +5739,47 @@ public class DevicePolicyManager {
        return false;
    }

    /**
     * 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>
+3 −0
Original line number Diff line number Diff line
@@ -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);

+1 −0
Original line number Diff line number Diff line
@@ -151,4 +151,5 @@ enum EventId {
  PROVISIONING_FLOW_TYPE = 124;
  CROSS_PROFILE_APPS_GET_TARGET_USER_PROFILES = 125;
  CROSS_PROFILE_APPS_START_ACTIVITY_AS_USER = 126;
  SET_AUTO_TIME = 127;
}
+0 −17
Original line number Diff line number Diff line
@@ -407,23 +407,6 @@ public class RestrictedLockUtilsInternal extends RestrictedLockUtils {
                ? enforcedAdmin : null;
    }

    /**
     * Checks if {@link android.app.admin.DevicePolicyManager#setAutoTimeRequired} is enforced
     * on the device.
     *
     * @return EnforcedAdmin Object containing the device owner component and
     * userId the device owner is running as, or {@code null} setAutoTimeRequired is not enforced.
     */
    public static EnforcedAdmin checkIfAutoTimeRequired(Context context) {
        DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(
                Context.DEVICE_POLICY_SERVICE);
        if (dpm == null || !dpm.getAutoTimeRequired()) {
            return null;
        }
        ComponentName adminComponent = dpm.getDeviceOwnerComponentOnCallingUser();
        return new EnforcedAdmin(adminComponent, getUserHandleOf(UserHandle.myUserId()));
    }

    /**
     * Checks if an admin has enforced minimum password quality requirements on the given user.
     *
Loading