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

Commit 869a67c0 authored by Michael Wright's avatar Michael Wright
Browse files

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
parent 9e05f91c
Loading
Loading
Loading
Loading
+27 −2
Original line number Original line Diff line number Diff line
@@ -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_RECENTS = 9;
    private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
    private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
    private static final int MSG_HIDE_BOOT_MESSAGE = 11;
    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 {
    private class PolicyHandler extends Handler {
        @Override
        @Override
@@ -590,6 +591,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                case MSG_HIDE_BOOT_MESSAGE:
                case MSG_HIDE_BOOT_MESSAGE:
                    handleHideBootMessage();
                    handleHideBootMessage();
                    break;
                    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) {
        } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
            if (!down) {
            if (!down) {
                Intent voiceIntent;
                Intent voiceIntent;
                if (!keyguardOn && mPowerManager.isInteractive()) {
                if (!keyguardOn) {
                    voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
                    voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
                } else {
                } else {
                    voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
                    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);
                mContext.startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
            }
            }
@@ -4440,6 +4444,19 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                }
                }
                break;
                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) {
        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() {
    BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
        @Override
        @Override
        public void onReceive(Context context, Intent intent) {
        public void onReceive(Context context, Intent intent) {