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

Commit 92a33973 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Don't allow non-showOnLock activity to be next on finish." into pi-dev

parents bb668a2b 86918964
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
@@ -325,13 +325,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();
@@ -340,7 +339,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);
@@ -359,6 +358,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)
@@ -370,6 +375,13 @@ 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 */));
    }
    }


    /**
    /**