Merge "Fix CTRL-SHIFT-SPACE shortcut" into udc-dev

This commit is contained in:
Adrian Roos
2023-02-21 10:02:36 +00:00
committed by Android (Google) Code Review
3 changed files with 30 additions and 5 deletions

View File

@@ -3409,7 +3409,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
case KeyEvent.KEYCODE_SPACE: case KeyEvent.KEYCODE_SPACE:
if (down && repeatCount == 0) { if (down && repeatCount == 0) {
// Handle keyboard layout switching. (CTRL + SPACE) // Handle keyboard layout switching. (CTRL + SPACE)
if (KeyEvent.metaStateHasModifiers(metaState, KeyEvent.META_CTRL_ON)) { if (KeyEvent.metaStateHasModifiers(metaState & ~KeyEvent.META_SHIFT_MASK,
KeyEvent.META_CTRL_ON)) {
int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1; int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction); mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
return true; return true;

View File

@@ -27,6 +27,7 @@ import static android.view.KeyEvent.KEYCODE_META_LEFT;
import static android.view.KeyEvent.KEYCODE_N; import static android.view.KeyEvent.KEYCODE_N;
import static android.view.KeyEvent.KEYCODE_P; import static android.view.KeyEvent.KEYCODE_P;
import static android.view.KeyEvent.KEYCODE_S; import static android.view.KeyEvent.KEYCODE_S;
import static android.view.KeyEvent.KEYCODE_SHIFT_LEFT;
import static android.view.KeyEvent.KEYCODE_SLASH; import static android.view.KeyEvent.KEYCODE_SLASH;
import static android.view.KeyEvent.KEYCODE_SPACE; import static android.view.KeyEvent.KEYCODE_SPACE;
import static android.view.KeyEvent.KEYCODE_TAB; import static android.view.KeyEvent.KEYCODE_TAB;
@@ -35,10 +36,15 @@ import static android.view.KeyEvent.KEYCODE_Z;
import android.content.Intent; import android.content.Intent;
import android.os.RemoteException; import android.os.RemoteException;
import android.platform.test.annotations.Presubmit;
import android.util.SparseArray; import android.util.SparseArray;
import androidx.test.filters.SmallTest;
import org.junit.Test; import org.junit.Test;
@Presubmit
@SmallTest
public class ModifierShortcutTests extends ShortcutKeyTestBase { public class ModifierShortcutTests extends ShortcutKeyTestBase {
private static final SparseArray<String> META_SHORTCUTS = new SparseArray<>(); private static final SparseArray<String> META_SHORTCUTS = new SparseArray<>();
static { static {
@@ -82,7 +88,16 @@ public class ModifierShortcutTests extends ShortcutKeyTestBase {
@Test @Test
public void testCtrlSpace() { public void testCtrlSpace() {
sendKeyCombination(new int[]{KEYCODE_CTRL_LEFT, KEYCODE_SPACE}, 0); sendKeyCombination(new int[]{KEYCODE_CTRL_LEFT, KEYCODE_SPACE}, 0);
mPhoneWindowManager.assertSwitchKeyboardLayout(); mPhoneWindowManager.assertSwitchKeyboardLayout(1);
}
/**
* CTRL + SHIFT + SPACE to switch keyboard layout backwards.
*/
@Test
public void testCtrlShiftSpace() {
sendKeyCombination(new int[]{KEYCODE_CTRL_LEFT, KEYCODE_SHIFT_LEFT, KEYCODE_SPACE}, 0);
mPhoneWindowManager.assertSwitchKeyboardLayout(-1);
} }
/** /**
@@ -91,7 +106,16 @@ public class ModifierShortcutTests extends ShortcutKeyTestBase {
@Test @Test
public void testMetaSpace() { public void testMetaSpace() {
sendKeyCombination(new int[]{KEYCODE_META_LEFT, KEYCODE_SPACE}, 0); sendKeyCombination(new int[]{KEYCODE_META_LEFT, KEYCODE_SPACE}, 0);
mPhoneWindowManager.assertSwitchKeyboardLayout(); mPhoneWindowManager.assertSwitchKeyboardLayout(1);
}
/**
* META + SHIFT + SPACE to switch keyboard layout backwards.
*/
@Test
public void testMetaShiftSpace() {
sendKeyCombination(new int[]{KEYCODE_META_LEFT, KEYCODE_SHIFT_LEFT, KEYCODE_SPACE}, 0);
mPhoneWindowManager.assertSwitchKeyboardLayout(-1);
} }
/** /**

View File

@@ -415,9 +415,9 @@ class TestPhoneWindowManager {
verify(mStatusBarManagerInternal).showRecentApps(anyBoolean()); verify(mStatusBarManagerInternal).showRecentApps(anyBoolean());
} }
void assertSwitchKeyboardLayout() { void assertSwitchKeyboardLayout(int direction) {
waitForIdle(); waitForIdle();
verify(mWindowManagerFuncsImpl).switchKeyboardLayout(anyInt(), anyInt()); verify(mWindowManagerFuncsImpl).switchKeyboardLayout(anyInt(), eq(direction));
} }
void assertTakeBugreport() { void assertTakeBugreport() {