From 0a7e2ea766971beccf29516f641007b86779be32 Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Tue, 5 Sep 2017 15:54:13 +0100 Subject: Ignore only internal volume keys when in VR mode. The concern here is that the elastic strap on some VR headsets will press the volume keys on the side of the device. Given that, external keys (e.g. bluetooth headsets, USB keyboards) aren't a concern and should be allowed to go through. I ran a couple quick traces and the initial fetch of the InputDevice takes ~0.1ms and each cache lookup following that takes ~0.01ms. This is probably okay to happen on the dispatcher thread since it's both rare and reasonably cheap, but if we find this to be a performance bottleneck in the future we could just add a flag to the input event itself denoting whether it comes from an internal or external input device. Fixes: 63909929 Test: flashed change, put the device in VR mode and saw that the side button volume keys didn't work but a USB-C headset's volume keys did. Change-Id: If3dfcd374abd79236c2c38e5b9439564c6b49ec8 --- .../java/com/android/server/policy/PhoneWindowManager.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java index 68913c3a887a..11873b4cf335 100644 --- a/services/core/java/com/android/server/policy/PhoneWindowManager.java +++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java @@ -3611,10 +3611,14 @@ public class PhoneWindowManager implements WindowManagerPolicy { return -1; } - // If the device is in Vr mode, drop the volume keys and don't - // forward it to the application/dispatch the audio event. + // If the device is in VR mode and keys are "internal" (e.g. on the side of the + // device), then drop the volume keys and don't forward it to the application/dispatch + // the audio event. if (mPersistentVrModeEnabled) { - return -1; + final InputDevice d = event.getDevice(); + if (d != null && !d.isExternal()) { + return -1; + } } } else if (keyCode == KeyEvent.KEYCODE_TAB && event.isMetaPressed()) { // Pass through keyboard navigation keys. -- cgit v1.2.3-59-g8ed1b