diff options
| author | 2020-12-14 17:00:13 +0000 | |
|---|---|---|
| committer | 2020-12-14 17:00:13 +0000 | |
| commit | f010d5dea2047b65d5d125219d2b2eac259302c8 (patch) | |
| tree | 56b46717c50ef290a3d9a8abe73f10461cec66d0 | |
| parent | c31c3a280790ee7bbd1f5274661946e7b7b94de1 (diff) | |
| parent | ea22f49eb3df5811402e1c1b10a5ac93b75796b1 (diff) | |
Merge "Add Assistant Triggered EventTime"
3 files changed, 36 insertions, 24 deletions
diff --git a/core/java/android/service/voice/VoiceInteractionSession.java b/core/java/android/service/voice/VoiceInteractionSession.java index 0b6d371d8235..c1b66c7b446e 100644 --- a/core/java/android/service/voice/VoiceInteractionSession.java +++ b/core/java/android/service/voice/VoiceInteractionSession.java @@ -1220,7 +1220,7 @@ public class VoiceInteractionSession implements KeyEvent.Callback, ComponentCall * your UI, which will eventually culminate in {@link #onShow}. This is similar to calling * {@link VoiceInteractionService#showSession VoiceInteractionService.showSession}. * @param args Arbitrary arguments that will be propagated {@link #onShow}. - * @param flags Indicates additional optional behavior that should be performed. May + * @param flags Indicates additional optional behavior that should be performed. May * be any combination of * {@link VoiceInteractionSession#SHOW_WITH_ASSIST VoiceInteractionSession.SHOW_WITH_ASSIST} and * {@link VoiceInteractionSession#SHOW_WITH_SCREENSHOT @@ -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}. */ diff --git a/core/java/com/android/internal/policy/PhoneWindow.java b/core/java/com/android/internal/policy/PhoneWindow.java index f89e52d4f91d..141dc79f4c93 100644 --- a/core/java/com/android/internal/policy/PhoneWindow.java +++ b/core/java/com/android/internal/policy/PhoneWindow.java @@ -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; diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java index cc4f5592cbb6..26915bc7fb22 100644 --- a/services/core/java/com/android/server/policy/PhoneWindowManager.java +++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java @@ -647,8 +647,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(); @@ -658,7 +658,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(); @@ -933,9 +933,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()); @@ -952,9 +953,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()); @@ -1187,7 +1189,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: @@ -1220,7 +1222,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; } } @@ -1623,7 +1625,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; @@ -1636,7 +1639,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; } @@ -1648,7 +1651,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(); @@ -2783,7 +2786,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; } @@ -3153,22 +3157,24 @@ 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); - } - if (hint != null) { - args.putBoolean(hint, true); - } + args = new Bundle(); + if (deviceId > Integer.MIN_VALUE) { + args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId); } + 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); } @@ -3790,7 +3796,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(); } |