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

Commit a44d7296 authored by Alex Johnston's avatar Alex Johnston
Browse files

Add new APIs setAutoTimeZone and getAutoTimeZone

* Added new API methods setAutoTimeZone and getAutoTimeZone.
* DPCs are recommended to combine these new APIs together with the DISALLOW_CONFIG_DATE_TIME
  restriction to prevent the user from changing auto time zone 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 zone toggle
      atest com.android.server.devicepolicy.DevicePolicyManagerTest
      atest com.android.cts.devicepolicy.MixedProfileOwnerTest#testSetAutoTimeZone
      atest com.android.cts.devicepolicy.ManagedProfileTest#testParentProfileApiDisabled

Change-Id: I841d31f76a848e9679d2d9087426e1d5bb7efd1d
parent f707567c
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -6732,6 +6732,7 @@ package android.app.admin {
    method @Deprecated @Nullable public String getApplicationRestrictionsManagingPackage(@NonNull android.content.ComponentName);
    method public boolean getAutoTime(@NonNull android.content.ComponentName);
    method @Deprecated public boolean getAutoTimeRequired();
    method public boolean getAutoTimeZone(@NonNull android.content.ComponentName);
    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);
@@ -6849,6 +6850,7 @@ package android.app.admin {
    method @Deprecated public void setApplicationRestrictionsManagingPackage(@NonNull android.content.ComponentName, @Nullable String) throws android.content.pm.PackageManager.NameNotFoundException;
    method public void setAutoTime(@NonNull android.content.ComponentName, boolean);
    method @Deprecated public void setAutoTimeRequired(@NonNull android.content.ComponentName, boolean);
    method public void setAutoTimeZone(@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);
+43 −0
Original line number Diff line number Diff line
@@ -5804,6 +5804,49 @@ 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 zone 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 zone. Instead, the network date
     * and time zone will be used.
     *
     * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
     * @param enabled Whether time zone 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 setAutoTimeZone(@NonNull ComponentName admin, boolean enabled) {
        throwIfParentInstance("setAutoTimeZone");
        if (mService != null) {
            try {
                mService.setAutoTimeZone(admin, enabled);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
        }
    }

    /**
     * @return true if auto time zone 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 getAutoTimeZone(@NonNull ComponentName admin) {
        throwIfParentInstance("getAutoTimeZone");
        if (mService != null) {
            try {
                return mService.getAutoTimeZone(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
@@ -298,6 +298,9 @@ interface IDevicePolicyManager {
    void setAutoTime(in ComponentName who, boolean enabled);
    boolean getAutoTime(in ComponentName who);

    void setAutoTimeZone(in ComponentName who, boolean enabled);
    boolean getAutoTimeZone(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
@@ -152,4 +152,5 @@ enum EventId {
  CROSS_PROFILE_APPS_GET_TARGET_USER_PROFILES = 125;
  CROSS_PROFILE_APPS_START_ACTIVITY_AS_USER = 126;
  SET_AUTO_TIME = 127;
  SET_AUTO_TIME_ZONE = 128;
}
+37 −1
Original line number Diff line number Diff line
@@ -7429,7 +7429,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
    }
    /**
     * Returns whether or auto time is used on the device or not.
     * Returns whether auto time is used on the device or not.
     */
    @Override
    public boolean getAutoTime(ComponentName who) {
@@ -7442,6 +7442,42 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        return mInjector.settingsGlobalGetInt(Global.AUTO_TIME, 0) > 0;
    }
    /**
     * Set whether auto time zone is enabled on the device.
     */
    @Override
    public void setAutoTimeZone(ComponentName who, boolean enabled) {
        if (!mHasFeature) {
            return;
        }
        Preconditions.checkNotNull(who, "ComponentName is null");
        // TODO (b/145286957) Refactor security checks
        enforceDeviceOwnerOrProfileOwnerOnUser0OrProfileOwnerOrganizationOwned();
        mInjector.binderWithCleanCallingIdentity(() ->
                mInjector.settingsGlobalPutInt(Global.AUTO_TIME_ZONE, enabled ? 1 : 0));
        DevicePolicyEventLogger
                .createEvent(DevicePolicyEnums.SET_AUTO_TIME_ZONE)
                .setAdmin(who)
                .setBoolean(enabled)
                .write();
    }
    /**
     * Returns whether auto time zone is used on the device or not.
     */
    @Override
    public boolean getAutoTimeZone(ComponentName who) {
        if (!mHasFeature) {
            return false;
        }
        Preconditions.checkNotNull(who, "ComponentName is null");
        enforceDeviceOwnerOrProfileOwnerOnUser0OrProfileOwnerOrganizationOwned();
        return mInjector.settingsGlobalGetInt(Global.AUTO_TIME_ZONE, 0) > 0;
    }
    @Override
    public void setForceEphemeralUsers(ComponentName who, boolean forceEphemeralUsers) {
        if (!mHasFeature) {
Loading