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

Commit a455e332 authored by Garfield Tan's avatar Garfield Tan
Browse files

Disallow windows in multi-window mode turn on screen

Bug: 160925539
Test: atest ActivityRecordTests
Test: Activity that has turnScreenOn and showWhenLocked both true can
turn on screen if launched in fullscreen mode, but can't turn on screen
if launched in freeform mode.

Change-Id: I9693b0adc3db6730c997923f23b784e386f71c99
parent 3d0dca5c
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -7465,7 +7465,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
    /**
     * Determines whether this ActivityRecord can turn the screen on. It checks whether the flag
     * {@link ActivityRecord#getTurnScreenOnFlag} is set and checks whether the ActivityRecord
     * should be visible depending on Keyguard state
     * should be visible depending on Keyguard and window state.
     *
     * @return true if the screen can be turned on, false otherwise.
     */
@@ -7474,8 +7474,9 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
            return false;
        }
        final ActivityStack stack = getRootTask();
        return stack != null &&
                stack.checkKeyguardVisibility(this, true /* shouldBeVisible */,
        return stack != null
                && !stack.inMultiWindowMode()
                && stack.checkKeyguardVisibility(this, true /* shouldBeVisible */,
                        stack.topRunningActivity() == this /* isTop */);
    }

+27 −1
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@
package com.android.server.wm;

import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION;
import static android.content.pm.ActivityInfo.CONFIG_SCREEN_LAYOUT;
@@ -65,9 +67,13 @@ import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;

import android.app.ActivityManager.TaskSnapshot;
@@ -405,7 +411,7 @@ public class ActivityRecordTests extends ActivityTestsBase {

    @Test
    public void ignoreRequestedOrientationInFreeformWindows() {
        mStack.setWindowingMode(WindowConfiguration.WINDOWING_MODE_FREEFORM);
        mStack.setWindowingMode(WINDOWING_MODE_FREEFORM);
        final Rect stableRect = new Rect();
        mStack.getDisplay().mDisplayContent.getStableRect(stableRect);

@@ -1657,6 +1663,26 @@ public class ActivityRecordTests extends ActivityTestsBase {
                .diff(wpc.getRequestedOverrideConfiguration()));
    }

    @Test
    public void testCanTurnScreenOn() {
        mStack.setWindowingMode(WINDOWING_MODE_FULLSCREEN);
        doReturn(true).when(mStack).checkKeyguardVisibility(
                same(mActivity), eq(true) /* shouldBeVisible */, anyBoolean());
        doReturn(true).when(mActivity).getTurnScreenOnFlag();

        assertTrue(mActivity.canTurnScreenOn());
    }

    @Test
    public void testFreeformWindowCantTurnScreenOn() {
        mStack.setWindowingMode(WINDOWING_MODE_FREEFORM);
        doReturn(true).when(mStack).checkKeyguardVisibility(
                same(mActivity), eq(true) /* shouldBeVisible */, anyBoolean());
        doReturn(true).when(mActivity).getTurnScreenOnFlag();

        assertFalse(mActivity.canTurnScreenOn());
    }

    /**
     * Creates an activity on display. For non-default display request it will also create a new
     * display with custom DisplayInfo.