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

Commit b8728418 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Remove ActivityRecord#okToShowLocked

ActivityRecord#showToCurrentUser also checks show-for-all-users flag
and current user/profile, so replace it by showToCurrentUser() that
will be consistent with the condition for window.

This eliminates unnecessary clearing binder identity and massive
invocations to StorageManagerService that acquires another lock.
In general the check becomes 10x faster.

The encryption check was added in commit 8558ec7d. Since start process
is changed to async, and the lock in handling user switch and
activities are separated, the recursive restart case no longer happens.
So it can be removed now.

Bug: 193661576
Test: atest RootWindowContainerTests
Test: Create a profile user with credential.
      Launch some activities of the profile user.
      Invoke UserManager#evictCredentialEncryptionKey and observe
      there should be no crash and exception from apps.

Change-Id: If088cf1712c7f784826ccbcf6c38aeff84f22e7e
parent 34ea03d9
Loading
Loading
Loading
Loading
+3 −18
Original line number Diff line number Diff line
@@ -285,7 +285,6 @@ import android.os.RemoteException;
import android.os.SystemClock;
import android.os.Trace;
import android.os.UserHandle;
import android.os.storage.StorageManager;
import android.service.contentcapture.ActivityEvent;
import android.service.dreams.DreamActivity;
import android.service.dreams.DreamManagerInternal;
@@ -730,7 +729,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
    // TODO: rename to mNoDisplay
    @VisibleForTesting
    boolean noDisplay;
    boolean mShowForAllUsers;
    final boolean mShowForAllUsers;
    // TODO: Make this final
    int mTargetSdk;

@@ -5305,7 +5304,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A

    void updateVisibilityIgnoringKeyguard(boolean behindFullscreenActivity) {
        visibleIgnoringKeyguard = (!behindFullscreenActivity || mLaunchTaskBehind)
                && okToShowLocked();
                && showToCurrentUser();
    }

    boolean shouldBeVisible() {
@@ -6342,22 +6341,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        return this;
    }

    /** Checks whether the activity should be shown for current user. */
    public boolean okToShowLocked() {
        // We cannot show activities when the device is locked and the application is not
        // encryption aware.
        if (!StorageManager.isUserKeyUnlocked(mUserId)
                && !info.applicationInfo.isEncryptionAware()) {
            return false;
        }

        return (info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0
                || (mTaskSupervisor.isCurrentProfileLocked(mUserId)
                && mAtmService.mAmInternal.isUserRunning(mUserId, 0 /* flags */));
    }

    boolean canBeTopRunning() {
        return !finishing && okToShowLocked();
        return !finishing && showToCurrentUser();
    }

    /**
+1 −1
Original line number Diff line number Diff line
@@ -2357,7 +2357,7 @@ class ActivityStarter {
        // of this in the record so that we can skip it when trying to find
        // the top running activity.
        mDoResume = doResume;
        if (!doResume || !r.okToShowLocked() || mLaunchTaskBehind) {
        if (!doResume || !r.showToCurrentUser() || mLaunchTaskBehind) {
            r.delayedResume = true;
            mDoResume = false;
        }
+0 −6
Original line number Diff line number Diff line
@@ -1872,12 +1872,6 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks {
        mHandler.obtainMessage(LAUNCH_TASK_BEHIND_COMPLETE, token).sendToTarget();
    }

    /** Checks whether the userid is a profile of the current user. */
    boolean isCurrentProfileLocked(int userId) {
        if (userId == mRootWindowContainer.mCurrentUser) return true;
        return mService.mAmInternal.isCurrentProfile(userId);
    }

    /**
     * Processes the activities to be stopped or destroyed. This should be called when the resumed
     * activities are idle or drawn.
+1 −1
Original line number Diff line number Diff line
@@ -1965,7 +1965,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent>

    private boolean startActivityForAttachedApplicationIfNeeded(ActivityRecord r,
            WindowProcessController app, ActivityRecord top) {
        if (r.finishing || !r.okToShowLocked() || !r.visibleIgnoringKeyguard || r.app != null
        if (r.finishing || !r.showToCurrentUser() || !r.visibleIgnoringKeyguard || r.app != null
                || app.mUid != r.info.applicationInfo.uid || !app.mName.equals(r.processName)) {
            return false;
        }
+2 −2
Original line number Diff line number Diff line
@@ -5159,7 +5159,7 @@ class Task extends TaskFragment {
                }

                final ActivityRecord prev = baseTask.getActivity(
                        a -> a.mStartingData != null && a.okToShowLocked());
                        a -> a.mStartingData != null && a.showToCurrentUser());
                r.showStartingWindow(prev, newTask, isTaskSwitch,
                        true /* startActivity */, sourceRecord);
            }
@@ -5530,7 +5530,7 @@ class Task extends TaskFragment {

            // Don't refocus if invisible to current user
            final ActivityRecord top = tr.getTopNonFinishingActivity();
            if (top == null || !top.okToShowLocked()) {
            if (top == null || !top.showToCurrentUser()) {
                positionChildAtTop(tr);
                if (top != null) {
                    mTaskSupervisor.mRecentTasks.add(top.getTask());
Loading