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

Commit 822a7fbd authored by Pavel Grafov's avatar Pavel Grafov
Browse files

Clarify time units for setManagedProfileMaximumTimeOff argument.

This CL addressess API Review comment.

Bug: 150685276
Test: compiles
Change-Id: I23107617004db7fab19a77331b17fd5dc16d69d8
parent ea494a7c
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -11961,17 +11961,17 @@ public class DevicePolicyManager {
     * must handle this intent.
     *
     * @param admin Which {@link DeviceAdminReceiver} this request is associated with
     * @param timeoutMs Maximum time the profile is allowed to be off in milliseconds or 0 if
     * @param timeoutMillis Maximum time the profile is allowed to be off in milliseconds or 0 if
     *        not limited.
     * @throws IllegalStateException if the profile owner doesn't have an activity that handles
     *        {@link #ACTION_CHECK_POLICY_COMPLIANCE}
     * @see #setPersonalAppsSuspended
     */
    public void setManagedProfileMaximumTimeOff(@NonNull ComponentName admin, long timeoutMs) {
    public void setManagedProfileMaximumTimeOff(@NonNull ComponentName admin, long timeoutMillis) {
        throwIfParentInstance("setManagedProfileMaximumTimeOff");
        if (mService != null) {
            try {
                mService.setManagedProfileMaximumTimeOff(admin, timeoutMs);
                mService.setManagedProfileMaximumTimeOff(admin, timeoutMillis);
            } catch (RemoteException re) {
                throw re.rethrowFromSystemServer();
            }
+16 −15
Original line number Diff line number Diff line
@@ -1202,7 +1202,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        // Whether the admin explicitly requires personal apps to be suspended
        boolean mSuspendPersonalApps = false;
        // Maximum time the profile owned by this admin can be off.
        long mProfileMaximumTimeOff = 0;
        long mProfileMaximumTimeOffMillis = 0;
        // Time by which the profile should be turned on according to System.currentTimeMillis().
        long mProfileOffDeadline = 0;
@@ -1443,10 +1443,11 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
            if (mSuspendPersonalApps) {
                writeAttributeValueToXml(out, TAG_SUSPEND_PERSONAL_APPS, mSuspendPersonalApps);
            }
            if (mProfileMaximumTimeOff != 0) {
                writeAttributeValueToXml(out, TAG_PROFILE_MAXIMUM_TIME_OFF, mProfileMaximumTimeOff);
            if (mProfileMaximumTimeOffMillis != 0) {
                writeAttributeValueToXml(out, TAG_PROFILE_MAXIMUM_TIME_OFF,
                        mProfileMaximumTimeOffMillis);
            }
            if (mProfileMaximumTimeOff != 0) {
            if (mProfileMaximumTimeOffMillis != 0) {
                writeAttributeValueToXml(out, TAG_PROFILE_OFF_DEADLINE, mProfileOffDeadline);
            }
            if (!TextUtils.isEmpty(mAlwaysOnVpnPackage)) {
@@ -1695,7 +1696,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                    mSuspendPersonalApps = Boolean.parseBoolean(
                            parser.getAttributeValue(null, ATTR_VALUE));
                } else if (TAG_PROFILE_MAXIMUM_TIME_OFF.equals(tag)) {
                    mProfileMaximumTimeOff =
                    mProfileMaximumTimeOffMillis =
                            Long.parseLong(parser.getAttributeValue(null, ATTR_VALUE));
                } else if (TAG_PROFILE_OFF_DEADLINE.equals(tag)) {
                    mProfileOffDeadline =
@@ -1933,8 +1934,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                pw.println(mCrossProfilePackages);
            pw.print("mSuspendPersonalApps=");
                pw.println(mSuspendPersonalApps);
            pw.print("mProfileMaximumTimeOff=");
                pw.println(mProfileMaximumTimeOff);
            pw.print("mProfileMaximumTimeOffMillis=");
                pw.println(mProfileMaximumTimeOffMillis);
            pw.print("mProfileOffDeadline=");
                pw.println(mProfileOffDeadline);
            pw.print("mAlwaysOnVpnPackage=");
@@ -15735,18 +15736,18 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        }
        boolean shouldSaveSettings = false;
        if (profileOwner.mProfileOffDeadline != 0
                && (profileOwner.mProfileMaximumTimeOff == 0 || unlocked)) {
                && (profileOwner.mProfileMaximumTimeOffMillis == 0 || unlocked)) {
            // There is a deadline but either there is no policy or the profile is unlocked -> clear
            // the deadline.
            Slog.i(LOG_TAG, "Profile off deadline is reset to zero");
            profileOwner.mProfileOffDeadline = 0;
            shouldSaveSettings = true;
        } else if (profileOwner.mProfileOffDeadline == 0
                && (profileOwner.mProfileMaximumTimeOff != 0 && !unlocked)) {
                && (profileOwner.mProfileMaximumTimeOffMillis != 0 && !unlocked)) {
            // There profile is locked and there is a policy, but the deadline is not set -> set the
            // deadline.
            Slog.i(LOG_TAG, "Profile off deadline is set.");
            profileOwner.mProfileOffDeadline = now + profileOwner.mProfileMaximumTimeOff;
            profileOwner.mProfileOffDeadline = now + profileOwner.mProfileMaximumTimeOffMillis;
            shouldSaveSettings = true;
        }
@@ -15847,7 +15848,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
    }
    @Override
    public void setManagedProfileMaximumTimeOff(ComponentName who, long timeoutMs) {
    public void setManagedProfileMaximumTimeOff(ComponentName who, long timeoutMillis) {
        final int userId = mInjector.userHandleGetCallingUserId();
        synchronized (getLockObject()) {
            final ActiveAdmin admin = getActiveAdminForCallerLocked(who,
@@ -15856,10 +15857,10 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
            // DO shouldn't be able to use this method.
            enforceProfileOwnerOfOrganizationOwnedDevice(admin);
            enforceHandlesCheckPolicyComplianceIntent(userId, admin.info.getPackageName());
            if (admin.mProfileMaximumTimeOff == timeoutMs) {
            if (admin.mProfileMaximumTimeOffMillis == timeoutMillis) {
                return;
            }
            admin.mProfileMaximumTimeOff = timeoutMs;
            admin.mProfileMaximumTimeOffMillis = timeoutMillis;
            saveSettingsLocked(userId);
        }
@@ -15869,7 +15870,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        DevicePolicyEventLogger
                .createEvent(DevicePolicyEnums.SET_MANAGED_PROFILE_MAXIMUM_TIME_OFF)
                .setAdmin(who)
                .setTimePeriod(timeoutMs)
                .setTimePeriod(timeoutMillis)
                .write();
    }
@@ -15893,7 +15894,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                    false /* parent */);
            // DO shouldn't be able to use this method.
            enforceProfileOwnerOfOrganizationOwnedDevice(admin);
            return admin.mProfileMaximumTimeOff;
            return admin.mProfileMaximumTimeOffMillis;
        }
    }