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

Commit 798cc31f authored by Vaibhav Devmurari's avatar Vaibhav Devmurari Committed by Android (Google) Code Review
Browse files

Merge "Fix broken tests for PWM" into main

parents 60e5898b aaa5aeed
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -2478,7 +2478,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                com.android.internal.R.integer.config_keyguardDrawnTimeout);
        mKeyguardDelegate = injector.getKeyguardServiceDelegate();
        initKeyCombinationRules();
        initSingleKeyGestureRules();
        initSingleKeyGestureRules(injector.getLooper());
        mSideFpsEventHandler = new SideFpsEventHandler(mContext, mHandler, mPowerManager);
    }

@@ -2749,8 +2749,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        }
    }

    private void initSingleKeyGestureRules() {
        mSingleKeyGestureDetector = SingleKeyGestureDetector.get(mContext);
    private void initSingleKeyGestureRules(Looper looper) {
        mSingleKeyGestureDetector = SingleKeyGestureDetector.get(mContext, looper);
        mSingleKeyGestureDetector.addRule(new PowerKeyRule());
        if (hasLongPressOnBackBehavior()) {
            mSingleKeyGestureDetector.addRule(new BackKeyRule());
+6 −6
Original line number Diff line number Diff line
@@ -179,8 +179,8 @@ public final class SingleKeyGestureDetector {
        }
    }

    static SingleKeyGestureDetector get(Context context) {
        SingleKeyGestureDetector detector = new SingleKeyGestureDetector();
    static SingleKeyGestureDetector get(Context context, Looper looper) {
        SingleKeyGestureDetector detector = new SingleKeyGestureDetector(looper);
        sDefaultLongPressTimeout = context.getResources().getInteger(
                com.android.internal.R.integer.config_globalActionsKeyTimeout);
        sDefaultVeryLongPressTimeout = context.getResources().getInteger(
@@ -188,8 +188,8 @@ public final class SingleKeyGestureDetector {
        return detector;
    }

    private SingleKeyGestureDetector() {
        mHandler = new KeyHandler();
    private SingleKeyGestureDetector(Looper looper) {
        mHandler = new KeyHandler(looper);
    }

    void addRule(SingleKeyRule rule) {
@@ -417,8 +417,8 @@ public final class SingleKeyGestureDetector {
    }

    private class KeyHandler extends Handler {
        KeyHandler() {
            super(Looper.myLooper());
        KeyHandler(Looper looper) {
            super(looper);
        }

        @Override
+1 −0
Original line number Diff line number Diff line
@@ -203,5 +203,6 @@ class ShortcutKeyTestBase {
                mPhoneWindowManager.dispatchUnhandledKey(keyEvent);
            }
        }
        mPhoneWindowManager.dispatchAllPendingEvents();
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import static org.junit.Assert.assertTrue;

import android.app.Instrumentation;
import android.content.Context;
import android.os.Looper;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Process;
@@ -80,7 +81,7 @@ public class SingleKeyGestureTests {
    public void setUp() {
        mInstrumentation.runOnMainSync(
                () -> {
                    mDetector = SingleKeyGestureDetector.get(mContext);
                    mDetector = SingleKeyGestureDetector.get(mContext, Looper.myLooper());
                    initSingleKeyGestureRules();
                });

+14 −17
Original line number Diff line number Diff line
@@ -118,7 +118,6 @@ import org.mockito.quality.Strictness;
import java.util.function.Supplier;

class TestPhoneWindowManager {
    private static final long SHORTCUT_KEY_DELAY_MILLIS = 150;
    private static final long TEST_SINGLE_KEY_DELAY_MILLIS
            = SingleKeyGestureDetector.MULTI_PRESS_TIMEOUT + 1000L * HW_TIMEOUT_MULTIPLIER;

@@ -188,7 +187,7 @@ class TestPhoneWindowManager {
        MockitoAnnotations.initMocks(this);
        mHandler = new Handler(mTestLooper.getLooper());
        mContext = mockingDetails(context).isSpy() ? context : spy(context);
        mHandler.post(() -> setUp(supportSettingsUpdate));
        setUp(supportSettingsUpdate);
        mTestLooper.dispatchAll();
    }

@@ -306,6 +305,10 @@ class TestPhoneWindowManager {
        mMockitoSession.finishMocking();
    }

    void dispatchAllPendingEvents() {
        mTestLooper.dispatchAll();
    }

    // Override accessibility setting and perform function.
    private void overrideLaunchAccessibility() {
        doReturn(true).when(mAccessibilityShortcutController)
@@ -446,6 +449,7 @@ class TestPhoneWindowManager {
        doNothing().when(mPhoneWindowManager).sendCloseSystemWindows();
        doReturn(true).when(mPhoneWindowManager).isUserSetupComplete();
        doReturn(mContext).when(mContext).createContextAsUser(any(), anyInt());
        doReturn(mSearchManager).when(mContext).getSystemService(eq(SearchManager.class));
    }

    void overrideSearchManager(SearchManager searchManager) {
@@ -500,29 +504,24 @@ class TestPhoneWindowManager {
     */
    void assertTakeScreenshotCalled() {
        mTestLooper.dispatchAll();
        verify(mDisplayPolicy, timeout(SHORTCUT_KEY_DELAY_MILLIS))
                .takeScreenshot(anyInt(), anyInt());
        verify(mDisplayPolicy).takeScreenshot(anyInt(), anyInt());
    }

    void assertShowGlobalActionsCalled() {
        mTestLooper.dispatchAll();
        verify(mPhoneWindowManager).showGlobalActions();
        verify(mGlobalActions, timeout(SHORTCUT_KEY_DELAY_MILLIS))
                .showDialog(anyBoolean(), anyBoolean());
        verify(mPowerManager, timeout(SHORTCUT_KEY_DELAY_MILLIS))
                .userActivity(anyLong(), anyBoolean());
        verify(mGlobalActions).showDialog(anyBoolean(), anyBoolean());
        verify(mPowerManager).userActivity(anyLong(), anyBoolean());
    }

    void assertVolumeMute() {
        mTestLooper.dispatchAll();
        verify(mAudioManagerInternal, timeout(SHORTCUT_KEY_DELAY_MILLIS))
                .silenceRingerModeInternal(eq("volume_hush"));
        verify(mAudioManagerInternal).silenceRingerModeInternal(eq("volume_hush"));
    }

    void assertAccessibilityKeychordCalled() {
        mTestLooper.dispatchAll();
        verify(mAccessibilityShortcutController,
                timeout(SHORTCUT_KEY_DELAY_MILLIS)).performAccessibilityShortcut();
        verify(mAccessibilityShortcutController).performAccessibilityShortcut();
    }

    void assertDreamRequest() {
@@ -532,14 +531,12 @@ class TestPhoneWindowManager {

    void assertPowerSleep() {
        mTestLooper.dispatchAll();
        verify(mPowerManager,
                timeout(SHORTCUT_KEY_DELAY_MILLIS)).goToSleep(anyLong(), anyInt(), anyInt());
        verify(mPowerManager).goToSleep(anyLong(), anyInt(), anyInt());
    }

    void assertPowerWakeUp() {
        mTestLooper.dispatchAll();
        verify(mPowerManager,
                timeout(SHORTCUT_KEY_DELAY_MILLIS)).wakeUp(anyLong(), anyInt(), anyString());
        verify(mPowerManager).wakeUp(anyLong(), anyInt(), anyString());
    }

    void assertNoPowerSleep() {
@@ -556,7 +553,7 @@ class TestPhoneWindowManager {

    void assertSearchManagerLaunchAssist() {
        mTestLooper.dispatchAll();
        verify(mSearchManager, timeout(SHORTCUT_KEY_DELAY_MILLIS)).launchAssist(any());
        verify(mSearchManager).launchAssist(any());
    }

    void assertLaunchCategory(String category) {