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

Commit 5e52a312 authored by Antony Sargent's avatar Antony Sargent
Browse files

Don't show KeyguardPresentation on non-default group displays

Bug: 175919666
Test: atest KeyguardDisplayManagerTest MultiDisplayKeyguardTests MultiDisplayLockedKeyguardTests
Change-Id: Ia860288c972a1a4a9a2f4d993ac95d025edd5793
parent 136109f1
Loading
Loading
Loading
Loading
+14 −2
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@
package com.android.keyguard;
package com.android.keyguard;


import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.Display.DEFAULT_DISPLAY_GROUP;


import android.app.Presentation;
import android.app.Presentation;
import android.content.Context;
import android.content.Context;
@@ -116,6 +117,14 @@ public class KeyguardDisplayManager {
            if (DEBUG) Log.i(TAG, "Do not show KeyguardPresentation on a private display");
            if (DEBUG) Log.i(TAG, "Do not show KeyguardPresentation on a private display");
            return false;
            return false;
        }
        }
        if (mTmpDisplayInfo.displayGroupId != DEFAULT_DISPLAY_GROUP) {
            if (DEBUG) {
                Log.i(TAG,
                        "Do not show KeyguardPresentation on a non-default group display");
            }
            return false;
        }

        return true;
        return true;
    }
    }
    /**
    /**
@@ -130,8 +139,7 @@ public class KeyguardDisplayManager {
        final int displayId = display.getDisplayId();
        final int displayId = display.getDisplayId();
        Presentation presentation = mPresentations.get(displayId);
        Presentation presentation = mPresentations.get(displayId);
        if (presentation == null) {
        if (presentation == null) {
            final Presentation newPresentation = new KeyguardPresentation(mContext, display,
            final Presentation newPresentation = createPresentation(display);
                    mKeyguardStatusViewComponentFactory);
            newPresentation.setOnDismissListener(dialog -> {
            newPresentation.setOnDismissListener(dialog -> {
                if (newPresentation.equals(mPresentations.get(displayId))) {
                if (newPresentation.equals(mPresentations.get(displayId))) {
                    mPresentations.remove(displayId);
                    mPresentations.remove(displayId);
@@ -152,6 +160,10 @@ public class KeyguardDisplayManager {
        return false;
        return false;
    }
    }


    KeyguardPresentation createPresentation(Display display) {
        return new KeyguardPresentation(mContext, display, mKeyguardStatusViewComponentFactory);
    }

    /**
    /**
     * @param displayId The id of the display to hide the presentation off.
     * @param displayId The id of the display to hide the presentation off.
     */
     */
+130 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.keyguard;

import static android.view.DisplayAdjustments.DEFAULT_DISPLAY_ADJUSTMENTS;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.hardware.display.DisplayManager;
import android.hardware.display.DisplayManagerGlobal;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.view.Display;
import android.view.DisplayInfo;

import androidx.test.filters.SmallTest;

import com.android.keyguard.dagger.KeyguardStatusViewComponent;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.navigationbar.NavigationBarController;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import java.util.concurrent.Executor;

@SmallTest
@RunWith(AndroidTestingRunner.class)
@TestableLooper.RunWithLooper
public class KeyguardDisplayManagerTest extends SysuiTestCase {

    @Mock
    private KeyguardStatusViewComponent.Factory mKeyguardStatusViewComponentFactory;

    @Mock
    private DisplayManager mDisplayManager;

    @Mock
    private KeyguardDisplayManager.KeyguardPresentation mKeyguardPresentation;

    private Executor mBackgroundExecutor = Runnable::run;
    private KeyguardDisplayManager mManager;

    // The default and secondary displays are both in the default group
    private Display mDefaultDisplay;
    private Display mSecondaryDisplay;

    // This display is in a different group from the default and secondary displays.
    private Display mDifferentGroupDisplay;

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        mContext.addMockSystemService(DisplayManager.class, mDisplayManager);
        mDependency.injectMockDependency(NavigationBarController.class);
        mManager = spy(new KeyguardDisplayManager(mContext, mKeyguardStatusViewComponentFactory,
                mBackgroundExecutor));
        doReturn(mKeyguardPresentation).when(mManager).createPresentation(any());

        mDefaultDisplay = new Display(DisplayManagerGlobal.getInstance(), Display.DEFAULT_DISPLAY,
                new DisplayInfo(), DEFAULT_DISPLAY_ADJUSTMENTS);
        mSecondaryDisplay = new Display(DisplayManagerGlobal.getInstance(),
                Display.DEFAULT_DISPLAY + 1,
                new DisplayInfo(), DEFAULT_DISPLAY_ADJUSTMENTS);

        DisplayInfo differentGroupInfo = new DisplayInfo();
        differentGroupInfo.displayId = Display.DEFAULT_DISPLAY + 2;
        differentGroupInfo.displayGroupId = Display.DEFAULT_DISPLAY_GROUP + 1;
        mDifferentGroupDisplay = new Display(DisplayManagerGlobal.getInstance(),
                Display.DEFAULT_DISPLAY,
                differentGroupInfo, DEFAULT_DISPLAY_ADJUSTMENTS);
    }

    @Test
    public void testShow_defaultDisplayOnly() {
        when(mDisplayManager.getDisplays()).thenReturn(new Display[]{mDefaultDisplay});
        mManager.show();
        verify(mManager, never()).createPresentation(any());
    }

    @Test
    public void testShow_includeSecondaryDisplay() {
        when(mDisplayManager.getDisplays()).thenReturn(
                new Display[]{mDefaultDisplay, mSecondaryDisplay});
        mManager.show();
        verify(mManager, times(1)).createPresentation(eq(mSecondaryDisplay));
    }

    @Test
    public void testShow_includeNonDefaultGroupDisplay() {
        when(mDisplayManager.getDisplays()).thenReturn(
                new Display[]{mDefaultDisplay, mDifferentGroupDisplay});

        mManager.show();
        verify(mManager, never()).createPresentation(any());
    }

    @Test
    public void testShow_includeSecondaryAndNonDefaultGroupDisplays() {
        when(mDisplayManager.getDisplays()).thenReturn(
                new Display[]{mDefaultDisplay, mSecondaryDisplay, mDifferentGroupDisplay});

        mManager.show();
        verify(mManager, times(1)).createPresentation(eq(mSecondaryDisplay));
    }
}