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

Commit 86918964 authored by Bryce Lee's avatar Bryce Lee
Browse files

Don't allow non-showOnLock activity to be next on finish.

Previously, we required the next activity (determined by top running
activity) to be showOnLock in the case the keyguard was locked and
the current activity is finished. However, this was bypassed if the
focused stack had a top running activity.

This changelist applies the same restrictions to the aforementioned
activity.

Test: atest ActivityStackSupervisorTests#testTopRunningActivity
Change-Id: I70ae64e0b0f4765b383bce91017bb675d0376d31
Fixes: 76424176
parent fcefeb25
Loading
Loading
Loading
Loading
+21 −3
Original line number Original line Diff line number Diff line
@@ -1224,7 +1224,7 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D
    ActivityRecord topRunningActivityLocked(boolean considerKeyguardState) {
    ActivityRecord topRunningActivityLocked(boolean considerKeyguardState) {
        final ActivityStack focusedStack = mFocusedStack;
        final ActivityStack focusedStack = mFocusedStack;
        ActivityRecord r = focusedStack.topRunningActivityLocked();
        ActivityRecord r = focusedStack.topRunningActivityLocked();
        if (r != null) {
        if (r != null && isValidTopRunningActivity(r, considerKeyguardState)) {
            return r;
            return r;
        }
        }


@@ -1257,12 +1257,11 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D
                continue;
                continue;
            }
            }


            final boolean keyguardLocked = getKeyguardController().isKeyguardLocked();


            // This activity can be considered the top running activity if we are not
            // This activity can be considered the top running activity if we are not
            // considering the locked state, the keyguard isn't locked, or we can show when
            // considering the locked state, the keyguard isn't locked, or we can show when
            // locked.
            // locked.
            if (!considerKeyguardState || !keyguardLocked || topActivity.canShowWhenLocked()) {
            if (isValidTopRunningActivity(topActivity, considerKeyguardState)) {
                return topActivity;
                return topActivity;
            }
            }
        }
        }
@@ -1270,6 +1269,25 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D
        return null;
        return null;
    }
    }


    /**
     * Verifies an {@link ActivityRecord} can be the top activity based on keyguard state and
     * whether we are considering it.
     */
    private boolean isValidTopRunningActivity(ActivityRecord record,
            boolean considerKeyguardState) {
        if (!considerKeyguardState) {
            return true;
        }

        final boolean keyguardLocked = getKeyguardController().isKeyguardLocked();

        if (!keyguardLocked) {
            return true;
        }

        return record.canShowWhenLocked();
    }

    @VisibleForTesting
    @VisibleForTesting
    void getRunningTasks(int maxNum, List<RunningTaskInfo> list,
    void getRunningTasks(int maxNum, List<RunningTaskInfo> list,
            @ActivityType int ignoreActivityType, @WindowingMode int ignoreWindowingMode,
            @ActivityType int ignoreActivityType, @WindowingMode int ignoreWindowingMode,
+17 −5
Original line number Original line Diff line number Diff line
@@ -332,13 +332,12 @@ public class ActivityStackSupervisorTests extends ActivityTestsBase {
    }
    }


    /**
    /**
     * Verifies the correct activity is returned when querying the top running activity with an
     * Verifies the correct activity is returned when querying the top running activity.
     * empty focused stack.
     */
     */
    @Test
    @Test
    public void testNonFocusedTopRunningActivity() throws Exception {
    public void testTopRunningActivity() throws Exception {
        // Create stack to hold focus
        // Create stack to hold focus
        final ActivityStack focusedStack = mService.mStackSupervisor.getDefaultDisplay()
        final ActivityStack emptyStack = mService.mStackSupervisor.getDefaultDisplay()
                .createStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */);
                .createStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */);


        final KeyguardController keyguard = mSupervisor.getKeyguardController();
        final KeyguardController keyguard = mSupervisor.getKeyguardController();
@@ -347,7 +346,7 @@ public class ActivityStackSupervisorTests extends ActivityTestsBase {
        final ActivityRecord activity = new ActivityBuilder(mService).setCreateTask(true)
        final ActivityRecord activity = new ActivityBuilder(mService).setCreateTask(true)
                .setStack(stack).build();
                .setStack(stack).build();


        mSupervisor.mFocusedStack = focusedStack;
        mSupervisor.mFocusedStack = emptyStack;


        doAnswer((InvocationOnMock invocationOnMock) -> {
        doAnswer((InvocationOnMock invocationOnMock) -> {
            final SparseIntArray displayIds = invocationOnMock.<SparseIntArray>getArgument(0);
            final SparseIntArray displayIds = invocationOnMock.<SparseIntArray>getArgument(0);
@@ -366,6 +365,12 @@ public class ActivityStackSupervisorTests extends ActivityTestsBase {
        assertEquals(null, mService.mStackSupervisor.topRunningActivityLocked(
        assertEquals(null, mService.mStackSupervisor.topRunningActivityLocked(
                true /* considerKeyguardState */));
                true /* considerKeyguardState */));


        // Change focus to stack with activity.
        mSupervisor.mFocusedStack = stack;
        assertEquals(activity, mService.mStackSupervisor.topRunningActivityLocked());
        assertEquals(null, mService.mStackSupervisor.topRunningActivityLocked(
                true /* considerKeyguardState */));

        // Add activity that should be shown on the keyguard.
        // Add activity that should be shown on the keyguard.
        final ActivityRecord showWhenLockedActivity = new ActivityBuilder(mService)
        final ActivityRecord showWhenLockedActivity = new ActivityBuilder(mService)
                .setCreateTask(true)
                .setCreateTask(true)
@@ -377,5 +382,12 @@ public class ActivityStackSupervisorTests extends ActivityTestsBase {
        assertEquals(showWhenLockedActivity, mService.mStackSupervisor.topRunningActivityLocked());
        assertEquals(showWhenLockedActivity, mService.mStackSupervisor.topRunningActivityLocked());
        assertEquals(showWhenLockedActivity, mService.mStackSupervisor.topRunningActivityLocked(
        assertEquals(showWhenLockedActivity, mService.mStackSupervisor.topRunningActivityLocked(
                true /* considerKeyguardState */));
                true /* considerKeyguardState */));

        // Change focus back to empty stack
        mSupervisor.mFocusedStack = emptyStack;
        // Ensure the show when locked activity is returned when not the focused stack
        assertEquals(showWhenLockedActivity, mService.mStackSupervisor.topRunningActivityLocked());
        assertEquals(showWhenLockedActivity, mService.mStackSupervisor.topRunningActivityLocked(
                true /* considerKeyguardState */));
    }
    }
}
}