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

Commit e9b47b13 authored by William Xiao's avatar William Xiao
Browse files

Fix PhoneWindowManagerTests

The power short press unit tests related to the glanceable hub exercise
a code check that checks if the lock screen is disabled. Keyguard is
always disabled in test harness mode, meaning that automated runs of
these tests always fail, while local repros with atest did not.

Bug: 402588489
Fixes: 402588489
Test: atest PhoneWindowManagerTests
      enter test harness mode first with adb shell cmd testharness enable
Flag: NONE test fix
Change-Id: I6e600cc5906843112ebe0670df935dfcf28f9fc3
parent 05136c4c
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -115,7 +115,6 @@ import static com.android.server.wm.WindowManagerPolicyProto.SCREEN_ON_FULLY;
import static com.android.server.wm.WindowManagerPolicyProto.WINDOW_MANAGER_DRAW_COMPLETE;

import android.accessibilityservice.AccessibilityService;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SuppressLint;
import android.app.ActivityManager;
@@ -2312,6 +2311,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            return ActivityManager.getService();
        }

        LockPatternUtils getLockPatternUtils() {
            return new LockPatternUtils(mContext);
        }

        ButtonOverridePermissionChecker getButtonOverridePermissionChecker() {
            return new ButtonOverridePermissionChecker();
        }
@@ -2360,7 +2363,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        mAccessibilityShortcutController = injector.getAccessibilityShortcutController(
                mContext, new Handler(), mCurrentUserId);
        mGlobalActionsFactory = injector.getGlobalActionsFactory();
        mLockPatternUtils = new LockPatternUtils(mContext);
        mLockPatternUtils = injector.getLockPatternUtils();
        mLogger = new MetricsLogger();

        Resources res = mContext.getResources();
+11 −0
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@ import android.view.contentprotection.flags.Flags;
import androidx.test.filters.SmallTest;

import com.android.internal.util.test.LocalServiceKeeperRule;
import com.android.internal.widget.LockPatternUtils;
import com.android.server.input.InputManagerInternal;
import com.android.server.pm.UserManagerInternal;
import com.android.server.policy.keyguard.KeyguardServiceDelegate;
@@ -119,6 +120,8 @@ public class PhoneWindowManagerTests {
    private DisplayPolicy mDisplayPolicy;
    @Mock
    private KeyguardServiceDelegate mKeyguardServiceDelegate;
    @Mock
    private LockPatternUtils mLockPatternUtils;

    @Before
    public void setUp() {
@@ -253,6 +256,7 @@ public class PhoneWindowManagerTests {
    @Test
    public void powerPress_hubOrDreamOrSleep_goesToSleepFromDream() {
        when(mDisplayPolicy.isAwake()).thenReturn(true);
        when(mLockPatternUtils.isLockScreenDisabled(anyInt())).thenReturn(false);
        initPhoneWindowManager();

        // Set power button behavior.
@@ -274,6 +278,7 @@ public class PhoneWindowManagerTests {
    @Test
    public void powerPress_hubOrDreamOrSleep_hubAvailableLocks() {
        when(mDisplayPolicy.isAwake()).thenReturn(true);
        when(mLockPatternUtils.isLockScreenDisabled(anyInt())).thenReturn(false);
        mContext.getTestablePermissions().setPermission(android.Manifest.permission.DEVICE_POWER,
                PERMISSION_GRANTED);
        initPhoneWindowManager();
@@ -302,6 +307,7 @@ public class PhoneWindowManagerTests {
    @Test
    public void powerPress_hubOrDreamOrSleep_hubNotAvailableDreams() {
        when(mDisplayPolicy.isAwake()).thenReturn(true);
        when(mLockPatternUtils.isLockScreenDisabled(anyInt())).thenReturn(false);
        initPhoneWindowManager();

        // Set power button behavior.
@@ -345,6 +351,11 @@ public class PhoneWindowManagerTests {
            return mKeyguardServiceDelegate;
        }

        @Override
        LockPatternUtils getLockPatternUtils() {
            return mLockPatternUtils;
        }

        /**
         * {@code WindowWakeUpPolicy} registers a local service in its constructor, easier to just
         * mock it out so we don't have to unregister it after every test.