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

Commit d07438f3 authored by Esteban Talavera's avatar Esteban Talavera
Browse files

Fix exception when calling setPasswordExpirationTimeout

Prevent exception when calling setPasswordExpirationTimeout on the parent
DPM instance. Callen setExpirationAlarmCheckLocked with the parent userHandle
was breaking because getPasswordExpirationLocked was trying to call getProfiles
on a different user.

Bug: 26847085
Change-Id: I9d584573245aba65af7ecf236f2021b47afb5d7e
parent 5f09616e
Loading
Loading
Loading
Loading
+8 −9
Original line number Diff line number Diff line
@@ -194,7 +194,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {

    private static final long EXPIRATION_GRACE_PERIOD_MS = 5 * MS_PER_DAY; // 5 days, in ms

    protected static final String ACTION_EXPIRED_PASSWORD_NOTIFICATION
    private static final String ACTION_EXPIRED_PASSWORD_NOTIFICATION
            = "com.android.server.ACTION_EXPIRED_PASSWORD_NOTIFICATION";

    private static final int MONITORING_CERT_NOTIFICATION_ID = R.string.ssl_ca_cert_warning;
@@ -1688,8 +1688,8 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
     * Set an alarm for an upcoming event - expiration warning, expiration, or post-expiration
     * reminders.  Clears alarm if no expirations are configured.
     */
    private void setExpirationAlarmCheckLocked(Context context, int userHandle) {
        final long expiration = getPasswordExpirationLocked(null, userHandle, /* parent */ false);
    private void setExpirationAlarmCheckLocked(Context context, int userHandle, boolean parent) {
        final long expiration = getPasswordExpirationLocked(null, userHandle, parent);
        final long now = System.currentTimeMillis();
        final long timeToExpire = expiration - now;
        final long alarmTime;
@@ -1711,11 +1711,12 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {

        long token = mInjector.binderClearCallingIdentity();
        try {
            int affectedUserHandle = parent ? getProfileParentId(userHandle) : userHandle;
            AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
            PendingIntent pi = PendingIntent.getBroadcastAsUser(context, REQUEST_EXPIRE_PASSWORD,
                    new Intent(ACTION_EXPIRED_PASSWORD_NOTIFICATION),
                    PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT,
                    UserHandle.of(userHandle));
                    UserHandle.of(affectedUserHandle));
            am.cancel(pi);
            if (alarmTime != 0) {
                am.set(AlarmManager.RTC, alarmTime, pi);
@@ -2458,7 +2459,6 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
        synchronized (this) {
            final long now = System.currentTimeMillis();

            // Return the strictest policy across all participating admins.
            List<ActiveAdmin> admins = getActiveAdminsForLockscreenPoliciesLocked(
                    userHandle, /* parent */ false);
            final int N = admins.size();
@@ -2472,7 +2472,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
                            DeviceAdminReceiver.ACTION_PASSWORD_EXPIRING);
                }
            }
            setExpirationAlarmCheckLocked(mContext, userHandle);
            setExpirationAlarmCheckLocked(mContext, userHandle, /* parent */ false);
        }
    }

@@ -2945,8 +2945,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
            saveSettingsLocked(userHandle);

            // in case this is the first one, set the alarm on the appropriate user.
            int affectedUserHandle = parent ? getProfileParentId(userHandle) : userHandle;
            setExpirationAlarmCheckLocked(mContext, affectedUserHandle);
            setExpirationAlarmCheckLocked(mContext, userHandle, parent);
        }
    }

@@ -4275,7 +4274,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
                policy.mFailedPasswordAttempts = 0;
                saveSettingsLocked(userHandle);
                updatePasswordExpirationsLocked(userHandle);
                setExpirationAlarmCheckLocked(mContext, userHandle);
                setExpirationAlarmCheckLocked(mContext, userHandle, /* parent */ false);

                // Send a broadcast to each profile using this password as its primary unlock.
                sendAdminCommandForLockscreenPoliciesLocked(