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

Commit d79ffeed authored by Pavel Grafov's avatar Pavel Grafov
Browse files

Ask profile password before disabling quiet mode

With "Turn off work 2.0" when the profile is put into quiet mode
the user is not stopped and its storage is not locked. Because of
that it is not sufficient to check for storage state - if the
profile has separate challenge, always ask for it.

Also, mark such user as locked in TrustManager.

Bug: 258823777
Test: manual
Change-Id: Ie5d79c3b149b63cf198ee61d550f1c93356d8977
parent 9ee8a8cd
Loading
Loading
Loading
Loading
+13 −4
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import android.app.PendingIntent;
import android.app.StatsManager;
import android.app.admin.DevicePolicyEventLogger;
import android.app.admin.DevicePolicyManagerInternal;
import android.app.trust.TrustManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.IIntentReceiver;
@@ -1256,11 +1257,12 @@ public class UserManagerService extends IUserManager.Stub {
        final long identity = Binder.clearCallingIdentity();
        try {
            if (enableQuietMode) {
                setQuietModeEnabled(
                        userId, true /* enableQuietMode */, target, callingPackage);
                setQuietModeEnabled(userId, true /* enableQuietMode */, target, callingPackage);
                return true;
            }
            if (mLockPatternUtils.isManagedProfileWithUnifiedChallenge(userId)) {
            final boolean hasUnifiedChallenge =
                    mLockPatternUtils.isManagedProfileWithUnifiedChallenge(userId);
            if (hasUnifiedChallenge) {
                KeyguardManager km = mContext.getSystemService(KeyguardManager.class);
                // Normally only attempt to auto-unlock unified challenge if keyguard is not showing
                // (to stop turning profile on automatically via the QS tile), except when we
@@ -1273,7 +1275,7 @@ public class UserManagerService extends IUserManager.Stub {
            }
            final boolean needToShowConfirmCredential = !dontAskCredential
                    && mLockPatternUtils.isSecure(userId)
                    && !StorageManager.isUserKeyUnlocked(userId);
                    && (!hasUnifiedChallenge || !StorageManager.isUserKeyUnlocked(userId));
            if (needToShowConfirmCredential) {
                if (onlyIfCredentialNotRequired) {
                    return false;
@@ -1365,6 +1367,11 @@ public class UserManagerService extends IUserManager.Stub {
            // suspended.
            getPackageManagerInternal().setPackagesSuspendedForQuietMode(userId, enableQuietMode);

            if (enableQuietMode
                    && !mLockPatternUtils.isManagedProfileWithUnifiedChallenge(userId)) {
                mContext.getSystemService(TrustManager.class).setDeviceLockedForUser(userId, true);
            }

            if (!enableQuietMode && target != null) {
                try {
                    mContext.startIntentSender(target, null, 0, 0, 0);
@@ -1374,6 +1381,8 @@ public class UserManagerService extends IUserManager.Stub {
            }
        } else {
            // Old behavior: when quiet is enabled, profile user is stopped.
            // Old quiet mode behavior: profile user is stopped.
            // TODO(b/265683382) Remove once rollout complete.
            try {
                if (enableQuietMode) {
                    ActivityManager.getService().stopUser(userId, /* force= */ true, null);