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

Commit 6db7c7c2 authored by Yeabkal Wubshit's avatar Yeabkal Wubshit Committed by Android (Google) Code Review
Browse files

Merge "Fix StemKeyGestureTests" into main

parents 73ffd635 0397297f
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) {
@@ -5585,12 +5597,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