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

Commit 0397297f authored by Yeabkal Wubshit's avatar Yeabkal Wubshit
Browse files

Fix StemKeyGestureTests

StemKeyGestureTests was failing after ag/23249820, where the stem key
behaviors are fetched in PhoneWindowManager#updateSettings() (instead of
PhoneWindowManager#init()). Since updateSettings() was mocked out in
this test, the key behavior was not being read properly.

We now enable the updateSettings() method in PhoneWindowManager for
tests, and use the Setting values of the key press behaviors to
configure test behaviors.

Bug: 287995215
Test: atest WmTests:StemKeyGestureTests WmTests:PowerKeyGestureTests WmTests:SingleKeyGestureTests WmTests:ModifierShortcutTests WmTests:KeyCombinationManagerTests WmTests:CombinationKeyTests WmTests:PhoneWindowManagerTests
Change-Id: I9ef0ab5923e124b350497b2f176b34e4f275a47d
parent 36d7bddc
Loading
Loading
Loading
Loading
+14 −7
Original line number Diff line number Diff line
@@ -2656,7 +2656,19 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        }
    }

    public void updateSettings() {
    private void updateSettings() {
        updateSettings(null);
    }

    /**
     * Update provider Setting values on a given {@code handler}, or synchronously if {@code null}
     * is passed for handler.
     */
    void updateSettings(Handler handler) {
        if (handler != null) {
            handler.post(() -> updateSettings(null));
            return;
        }
        ContentResolver resolver = mContext.getContentResolver();
        boolean updateRotation = false;
        synchronized (mLock) {
@@ -5583,12 +5595,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        mDefaultDisplayRotation.updateOrientationListener();
        synchronized (mLock) {
            mSystemReady = true;
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    updateSettings();
                }
            });
            updateSettings(mHandler);
            // If this happens, for whatever reason, systemReady came later than systemBooted.
            // And keyguard should be already bound from systemBooted
            if (mSystemBooted) {
+6 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.view.ViewConfiguration;
import androidx.test.filters.MediumTest;
import androidx.test.runner.AndroidJUnit4;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

@@ -41,6 +42,11 @@ import org.junit.runner.RunWith;
public class CombinationKeyTests extends ShortcutKeyTestBase {
    private static final long A11Y_KEY_HOLD_MILLIS = 3500;

    @Before
    public void setUp() {
        setUpPhoneWindowManager();
    }

    /**
     * Power-VolDown to take screenshot.
     */
+6 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ import android.util.SparseArray;

import androidx.test.filters.SmallTest;

import org.junit.Before;
import org.junit.Test;

@Presubmit
@@ -61,6 +62,11 @@ public class ModifierShortcutTests extends ShortcutKeyTestBase {
        META_SHORTCUTS.append(KEYCODE_S, Intent.CATEGORY_APP_MESSAGING);
    }

    @Before
    public void setUp() {
        setUpPhoneWindowManager();
    }

    /**
     * Test meta+ shortcuts defined in bookmarks.xml.
     */
+6 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import static com.android.server.policy.PhoneWindowManager.SHORT_PRESS_POWER_GO_
import android.provider.Settings;
import android.view.Display;

import org.junit.Before;
import org.junit.Test;

/**
@@ -35,6 +36,11 @@ import org.junit.Test;
 *  atest WmTests:PowerKeyGestureTests
 */
public class PowerKeyGestureTests extends ShortcutKeyTestBase {
    @Before
    public void setUp() {
        setUpPhoneWindowManager();
    }

    /**
     * Power single press to turn screen on/off.
     */
+28 −5
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import static android.view.KeyEvent.META_SHIFT_RIGHT_ON;

import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;

import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.spy;
import static com.android.server.policy.WindowManagerPolicy.ACTION_PASS_TO_USER;

@@ -53,12 +54,17 @@ import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.ViewConfiguration;

import com.android.internal.util.test.FakeSettingsProvider;
import com.android.internal.util.test.FakeSettingsProviderRule;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;

import java.util.Map;

class ShortcutKeyTestBase {
    @Rule public FakeSettingsProviderRule mSettingsProviderRule = FakeSettingsProvider.rule();

    TestPhoneWindowManager mPhoneWindowManager;
    final Context mContext = spy(getInstrumentation().getTargetContext());

@@ -78,19 +84,36 @@ class ShortcutKeyTestBase {
        MODIFIER = unmodifiableMap(map);
    }

    @Before
    public void setUp() {
    /** Same as {@link setUpPhoneWindowManager(boolean)}, without supporting settings update. */
    protected final void setUpPhoneWindowManager() {
        setUpPhoneWindowManager(/* supportSettingsUpdate= */ false);
    }

    /**
     * Creates and sets up a {@link TestPhoneWindowManager} instance.
     *
     * <p>Subclasses must call this at the start of the test if they intend to interact with phone
     * window manager.
     *
     * @param supportSettingsUpdate {@code true} if this test should read and listen to provider
     *      settings values.
     */
    protected final void setUpPhoneWindowManager(boolean supportSettingsUpdate) {
        if (Looper.myLooper() == null) {
            Looper.prepare();
        }

        mPhoneWindowManager = new TestPhoneWindowManager(mContext);
        doReturn(mSettingsProviderRule.mockContentResolver(mContext))
                .when(mContext).getContentResolver();
        mPhoneWindowManager = new TestPhoneWindowManager(mContext, supportSettingsUpdate);
    }

    @After
    public void tearDown() {
        if (mPhoneWindowManager != null) {
            mPhoneWindowManager.tearDown();
        }
    }

    void sendKeyCombination(int[] keyCodes, long duration) {
        final long downTime = SystemClock.uptimeMillis();
Loading