From 869a67c0b1ed7fb485851edb99376c4e4099ceae Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Tue, 26 Aug 2014 19:33:06 -0700 Subject: [PATCH] Allow voice assist to function in a non-interactive state Currently the InputDispatcher blocks the VOICE_ASSIST key from being sent to the window manager when the system is in a non-interactive state. Move the key handling to interceptKeyBeforeQueueing to avoid this but also push off the behavior to a handler to avoid any potential blocking of the input queue as we call into other system services. Bug: 16292420 Change-Id: I5bbe3455f2af5249151127dede2204cf1f12a19f --- .../policy/impl/PhoneWindowManager.java | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java index c57563b2809cb..183653d541caf 100644 --- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java +++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java @@ -545,6 +545,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { private static final int MSG_DISPATCH_SHOW_RECENTS = 9; private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10; private static final int MSG_HIDE_BOOT_MESSAGE = 11; + private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12; private class PolicyHandler extends Handler { @Override @@ -590,6 +591,9 @@ public class PhoneWindowManager implements WindowManagerPolicy { case MSG_HIDE_BOOT_MESSAGE: handleHideBootMessage(); break; + case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK: + launchVoiceAssistWithWakeLock(msg.arg1 != 0); + break; } } } @@ -2342,11 +2346,11 @@ public class PhoneWindowManager implements WindowManagerPolicy { } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) { if (!down) { Intent voiceIntent; - if (!keyguardOn && mPowerManager.isInteractive()) { + if (!keyguardOn) { voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); } else { voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); - voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardOn); + voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true); } mContext.startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF); } @@ -4440,6 +4444,19 @@ public class PhoneWindowManager implements WindowManagerPolicy { } break; } + case KeyEvent.KEYCODE_VOICE_ASSIST: { + // Only do this if we would otherwise not pass it to the user. In that case, + // interceptKeyBeforeDispatching would apply a similar but different policy in + // order to invoke voice assist actions. Note that we need to make a copy of the + // key event here because the original key event will be recycled when we return. + if ((result & ACTION_PASS_TO_USER) == 0 && !down) { + mBroadcastWakeLock.acquire(); + Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK, + keyguardActive ? 1 : 0, 0); + msg.setAsynchronous(true); + msg.sendToTarget(); + } + } } if (useHapticFeedback) { @@ -4546,6 +4563,14 @@ public class PhoneWindowManager implements WindowManagerPolicy { } } + void launchVoiceAssistWithWakeLock(boolean keyguardActive) { + Intent voiceIntent = + new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); + voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive); + mContext.startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF); + mBroadcastWakeLock.release(); + } + BroadcastReceiver mDockReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) {