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

Commit bdc3961f authored by Ricky Wai's avatar Ricky Wai Committed by Android (Google) Code Review
Browse files

Merge "Fix work profile screen timeout policy" into nyc-dev

parents c2c19e34 035e9244
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -2287,6 +2287,23 @@ public class DevicePolicyManager {
        return 0;
    }

    /**
     * Returns maximum time to lock that applied by all profiles in this user. We do this because we
     * do not have a separate timeout to lock for work challenge only.
     *
     * @hide
     */
    public long getMaximumTimeToLockForUserAndProfiles(int userHandle) {
        if (mService != null) {
            try {
                return mService.getMaximumTimeToLockForUserAndProfiles(userHandle);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
        }
        return 0;
    }

    /**
     * Make the device lock immediately, as if the lock screen timeout has expired at the point of
     * this call.
+1 −0
Original line number Diff line number Diff line
@@ -80,6 +80,7 @@ interface IDevicePolicyManager {

    void setMaximumTimeToLock(in ComponentName who, long timeMs, boolean parent);
    long getMaximumTimeToLock(in ComponentName who, int userHandle, boolean parent);
    long getMaximumTimeToLockForUserAndProfiles(int userHandle);

    void lockNow(boolean parent);

+25 −43
Original line number Diff line number Diff line
@@ -459,35 +459,19 @@ public class RestrictedLockUtils {
        LockPatternUtils lockPatternUtils = new LockPatternUtils(context);
        EnforcedAdmin enforcedAdmin = null;
        final int userId = UserHandle.myUserId();
        if (lockPatternUtils.isSeparateProfileChallengeEnabled(userId)) {
            // userId is managed profile and has a separate challenge, only consider
            // the admins in that user.
            final List<ComponentName> admins = dpm.getActiveAdminsAsUser(userId);
            if (admins == null) {
                return null;
            }
            for (ComponentName admin : admins) {
                if (dpm.getMaximumTimeToLock(admin, userId) > 0) {
                    if (enforcedAdmin == null) {
                        enforcedAdmin = new EnforcedAdmin(admin, userId);
                    } else {
                        return EnforcedAdmin.MULTIPLE_ENFORCED_ADMIN;
                    }
                }
            }
        } else {
            // Return all admins for this user and the profiles that are visible from this
            // user that do not use a separate work challenge.
            final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
            for (UserInfo userInfo : um.getProfiles(userId)) {
        final UserManager um = UserManager.get(context);
        final List<UserInfo> profiles = um.getProfiles(userId);
        final int profilesSize = profiles.size();
        // As we do not have a separate screen lock timeout settings for work challenge,
        // we need to combine all profiles maximum time to lock even work challenge is
        // enabled.
        for (int i = 0; i < profilesSize; i++) {
            final UserInfo userInfo = profiles.get(i);
            final List<ComponentName> admins = dpm.getActiveAdminsAsUser(userInfo.id);
            if (admins == null) {
                continue;
            }
                final boolean isSeparateProfileChallengeEnabled =
                        lockPatternUtils.isSeparateProfileChallengeEnabled(userInfo.id);
            for (ComponentName admin : admins) {
                    if (!isSeparateProfileChallengeEnabled) {
                if (dpm.getMaximumTimeToLock(admin, userInfo.id) > 0) {
                    if (enforcedAdmin == null) {
                        enforcedAdmin = new EnforcedAdmin(admin, userInfo.id);
@@ -500,11 +484,10 @@ public class RestrictedLockUtils {
                    // has set policy on the parent admin.
                    continue;
                }
                    }
                if (userInfo.isManagedProfile()) {
                    // If userInfo.id is a managed profile, we also need to look at
                    // the policies set on the parent.
                        DevicePolicyManager parentDpm = dpm.getParentProfileInstance(userInfo);
                    final DevicePolicyManager parentDpm = dpm.getParentProfileInstance(userInfo);
                    if (parentDpm.getMaximumTimeToLock(admin, userInfo.id) > 0) {
                        if (enforcedAdmin == null) {
                            enforcedAdmin = new EnforcedAdmin(admin, userInfo.id);
@@ -515,7 +498,6 @@ public class RestrictedLockUtils {
                }
            }
        }
        }
        return enforcedAdmin;
    }

+1 −1
Original line number Diff line number Diff line
@@ -804,7 +804,7 @@ public class KeyguardViewMediator extends SystemUI {

        // From DevicePolicyAdmin
        final long policyTimeout = mLockPatternUtils.getDevicePolicyManager()
                .getMaximumTimeToLock(null, userId);
                .getMaximumTimeToLockForUserAndProfiles(userId);

        long timeout;

+1 −1
Original line number Diff line number Diff line
@@ -375,7 +375,7 @@ public class TrustAgentWrapper {
                } else {
                    mTrustAgentService.onConfigure(Collections.EMPTY_LIST, null);
                }
                final long maxTimeToLock = dpm.getMaximumTimeToLock(null);
                final long maxTimeToLock = dpm.getMaximumTimeToLockForUserAndProfiles(mUserId);
                if (maxTimeToLock != mMaximumTimeToLock) {
                    // If the timeout changes, cancel the alarm and send a timeout event to have
                    // the agent re-evaluate trust.
Loading