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

Commit 201dd116 authored by Pavel Grafov's avatar Pavel Grafov
Browse files

Fix locked profile activity hiding logic

The aim of this code is to avoid asking the user to solve two
lock screens in a row (the keyguard and a work challenge) in case
when the profile has a separate PIN/pattern/password and a
profile activity is on the screen when the phone gets locked.

This CL solves two issues with existing code:
* currently it doesn't consider whether the acivity is a profile
  activity - will go to home screen even if the activity is personal.
  This is solved by checking mLastResumedActivity.mUserId
* doesn't work when the profile locked status is updated before keyguard
  status, which happens on power button press.
  This is solved by invoing the code on keyguard state update.

The code could have been more optimal by not checking user locked or
keyguard state twice, but at the cost of duplication.

Bug: 219752817
Bug: 143759666
Test: manual with TestDPC
Test: atest ActivityTaskManagerServiceTests

Change-Id: I15a9786c63653cacfe2f3042a164f1a1c9ea34c8
parent 2c2a2cf0
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -7284,7 +7284,7 @@ public class ActivityManagerService extends IActivityManager.Stub
    @Override
    public void notifyLockedProfile(@UserIdInt int userId) {
        mAtmInternal.notifyLockedProfile(userId, mUserController.getCurrentUserId());
        mAtmInternal.notifyLockedProfile(userId);
    }
    @Override
+1 −1
Original line number Diff line number Diff line
@@ -465,7 +465,7 @@ public abstract class ActivityTaskManagerInternal {
    public abstract boolean attachApplication(WindowProcessController wpc) throws RemoteException;

    /** @see IActivityManager#notifyLockedProfile(int) */
    public abstract void notifyLockedProfile(@UserIdInt int userId, int currentUserId);
    public abstract void notifyLockedProfile(@UserIdInt int userId);

    /** @see IActivityManager#startConfirmDeviceCredentialIntent(Intent, Bundle) */
    public abstract void startConfirmDeviceCredentialIntent(Intent intent, Bundle options);
+24 −5
Original line number Diff line number Diff line
@@ -241,6 +241,7 @@ import android.window.SplashScreenView.SplashScreenViewParcelable;
import android.window.TaskSnapshot;

import com.android.internal.R;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.app.IVoiceInteractor;
import com.android.internal.app.ProcessMap;
@@ -2962,6 +2963,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
                    mKeyguardController.setKeyguardShown(displayContent.getDisplayId(),
                            keyguardShowing, aodShowing);
                });
                maybeHideLockedProfileActivityLocked();
            } finally {
                Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
                Binder.restoreCallingIdentity(ident);
@@ -2975,6 +2977,26 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
        });
    }

    /**
     * Hides locked profile activity by going to home screen to avoid showing the user two lock
     * screens in a row.
     */
    @GuardedBy("mGlobalLock")
    private void maybeHideLockedProfileActivityLocked() {
        if (!mKeyguardController.isKeyguardLocked(DEFAULT_DISPLAY)
                || mLastResumedActivity == null) {
            return;
        }
        var userInfo = mUserManager.getUserInfo(mLastResumedActivity.mUserId);
        if (userInfo == null || !userInfo.isManagedProfile()) {
            return;
        }
        if (mAmInternal.shouldConfirmCredentials(mLastResumedActivity.mUserId)) {
            mInternal.startHomeActivity(
                    mAmInternal.getCurrentUserId(), "maybeHideLockedProfileActivityLocked");
        }
    }

    // The caller MUST NOT hold the global lock.
    public void onScreenAwakeChanged(boolean isAwake) {
        mH.post(() -> {
@@ -6344,7 +6366,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
        }

        @Override
        public void notifyLockedProfile(@UserIdInt int userId, int currentUserId) {
        public void notifyLockedProfile(@UserIdInt int userId) {
            try {
                if (!AppGlobals.getPackageManager().isUidPrivileged(Binder.getCallingUid())) {
                    throw new SecurityException("Only privileged app can call notifyLockedProfile");
@@ -6357,10 +6379,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
                final long ident = Binder.clearCallingIdentity();
                try {
                    if (mAmInternal.shouldConfirmCredentials(userId)) {
                        if (mKeyguardController.isKeyguardLocked(DEFAULT_DISPLAY)) {
                            // Showing launcher to avoid user entering credential twice.
                            startHomeActivity(currentUserId, "notifyLockedProfile");
                        }
                        maybeHideLockedProfileActivityLocked();
                        mRootWindowContainer.lockAllProfileTasks(userId);
                    }
                } finally {