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

Commit ea22f49e authored by Johanna Ye's avatar Johanna Ye
Browse files

Add Assistant Triggered EventTime

Test: ADT3 on adt3-userdebug, with RVIS as the default AssistService and
VoiceInteractionService reporting the intent extra.

12-09 17:16:19.826  8809  8809 I #AssistSession: TVTS_RVIS android.intent.extra.TIME: 926771
12-09 17:16:19.826  8809  8809 I #AssistSession: TVTS_RVIS invocation_time_ms: 926773
12-09 17:16:19.826  8809  8809 I #AssistSession: TVTS_RVIS ASSIST_INPUT_DEVICE_ID: 7
12-09 17:16:19.826  8809  8809 I #AssistSession: TVTS_RVIS invocation_phone_state: 5
12-09 17:16:19.840  8809  8809 I #AssistSession: [TVTS] Showing Voiceplate: 926792
12-09 17:16:19.932  8809  8832 I AudioSourceManager: [TVTS][Legacy] micOpen
12-09 17:16:20.162  8809  8856 I AudioSourceManager: [TVTS][Legacy] Read non-zero bytes

Bug: 129355484

Change-Id: I653deac41e105e04f56e03aec0fa80d8d7eb5b54
parent a64af976
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -1583,6 +1583,11 @@ public class VoiceInteractionSession implements KeyEvent.Callback, ComponentCall
     *
     * @param args The arguments that were supplied to
     * {@link VoiceInteractionService#showSession VoiceInteractionService.showSession}.
     * Some example keys include : "invocation_type", "invocation_phone_state",
     * "invocation_time_ms", Intent.EXTRA_TIME ("android.intent.extra.TIME") indicating timing
     * in milliseconds of the KeyEvent that triggered Assistant and
     * Intent.EXTRA_ASSIST_INPUT_DEVICE_ID (android.intent.extra.ASSIST_INPUT_DEVICE_ID)
     *  referring to the device that sent the request.
     * @param showFlags The show flags originally provided to
     * {@link VoiceInteractionService#showSession VoiceInteractionService.showSession}.
     */
+1 −0
Original line number Diff line number Diff line
@@ -3140,6 +3140,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
            // On TVs, if the app doesn't implement search, we want to launch assist.
            Bundle args = new Bundle();
            args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, event.getDeviceId());
            args.putLong(Intent.EXTRA_TIME, event.getEventTime());
            ((SearchManager) getContext().getSystemService(Context.SEARCH_SERVICE))
                    .launchAssist(args);
            return true;
+29 −23
Original line number Diff line number Diff line
@@ -648,8 +648,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    break;
                case MSG_LAUNCH_ASSIST:
                    final int deviceId = msg.arg1;
                    final String hint = (String) msg.obj;
                    launchAssistAction(hint, deviceId);
                    final Long eventTime = (Long) msg.obj;
                    launchAssistAction(null /* hint */, deviceId, eventTime);
                    break;
                case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
                    launchVoiceAssistWithWakeLock();
@@ -659,7 +659,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    finishPowerKeyPress();
                    break;
                case MSG_POWER_LONG_PRESS:
                    powerLongPress();
                    powerLongPress((Long) msg.obj /* eventTime */);
                    break;
                case MSG_POWER_VERY_LONG_PRESS:
                    powerVeryLongPress();
@@ -934,9 +934,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                // Wait for a long press or for the button to be released to decide what to do.
                if (hasLongPressOnPowerBehavior()) {
                    if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
                        powerLongPress();
                        powerLongPress(event.getEventTime());
                    } else {
                        Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
                        Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS,
                                event.getEventTime());
                        msg.setAsynchronous(true);
                        mHandler.sendMessageDelayed(msg,
                                ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
@@ -953,9 +954,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {

                if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
                    if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
                        powerLongPress();
                        powerLongPress(event.getEventTime());
                    } else {
                        Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
                        Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS,
                                event.getEventTime());
                        msg.setAsynchronous(true);
                        mHandler.sendMessageDelayed(msg,
                                ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
@@ -1188,7 +1190,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        return 1;
    }

    private void powerLongPress() {
    private void powerLongPress(long eventTime) {
        final int behavior = getResolvedLongPressOnPowerBehavior();
        switch (behavior) {
            case LONG_PRESS_POWER_NOTHING:
@@ -1221,7 +1223,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, false,
                        "Power - Long Press - Go To Assistant");
                final int powerKeyDeviceId = Integer.MIN_VALUE;
                launchAssistAction(null, powerKeyDeviceId);
                launchAssistAction(null, powerKeyDeviceId, eventTime);
                break;
        }
    }
@@ -1624,7 +1626,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
                if (!keyguardOn) {
                    // Post to main thread to avoid blocking input pipeline.
                    mHandler.post(() -> handleLongPressOnHome(event.getDeviceId()));
                    mHandler.post(() -> handleLongPressOnHome(event.getDeviceId(),
                            event.getEventTime()));
                }
            }
            return -1;
@@ -1637,7 +1640,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            }
        }

        private void handleLongPressOnHome(int deviceId) {
        private void handleLongPressOnHome(int deviceId, long eventTime) {
            if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_NOTHING) {
                return;
            }
@@ -1649,7 +1652,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    launchAllAppsAction();
                    break;
                case LONG_PRESS_HOME_ASSIST:
                    launchAssistAction(null, deviceId);
                    launchAssistAction(null, deviceId, eventTime);
                    break;
                case LONG_PRESS_HOME_NOTIFICATION_PANEL:
                    toggleNotificationPanel();
@@ -2791,7 +2794,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            if (down) {
                mPendingMetaAction = true;
            } else if (mPendingMetaAction) {
                launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId());
                launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId(),
                        event.getEventTime());
            }
            return -1;
        }
@@ -3154,14 +3158,15 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    // various parts of the UI.

    /** Asks the status bar to startAssist(), usually a full "assistant" interface */
    private void launchAssistAction(String hint, int deviceId) {
    private void launchAssistAction(String hint, int deviceId, long eventTime) {
        sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
        if (!isUserSetupComplete()) {
            // Disable opening assist window during setup
            return;
        }

        // Add Intent Extra data.
        Bundle args = null;
        if (deviceId > Integer.MIN_VALUE || hint != null) {
        args = new Bundle();
        if (deviceId > Integer.MIN_VALUE) {
            args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId);
@@ -3169,7 +3174,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        if (hint != null) {
            args.putBoolean(hint, true);
        }
        }
        args.putLong(Intent.EXTRA_TIME, eventTime);

        ((SearchManager) mContext.createContextAsUser(UserHandle.of(mCurrentUserId), 0)
                .getSystemService(Context.SEARCH_SERVICE)).launchAssist(args);
    }
@@ -3791,7 +3797,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                final boolean longPressed = event.getRepeatCount() > 0;
                if (down && !longPressed) {
                    Message msg = mHandler.obtainMessage(MSG_LAUNCH_ASSIST, event.getDeviceId(),
                            0 /* unused */, null /* hint */);
                            0 /* unused */, event.getEventTime() /* eventTime */);
                    msg.setAsynchronous(true);
                    msg.sendToTarget();
                }