Merge "Add Assistant Triggered EventTime"
diff --git a/core/java/android/service/voice/VoiceInteractionSession.java b/core/java/android/service/voice/VoiceInteractionSession.java
index 0b6d371..c1b66c7 100644
--- a/core/java/android/service/voice/VoiceInteractionSession.java
+++ b/core/java/android/service/voice/VoiceInteractionSession.java
@@ -1220,7 +1220,7 @@
* 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 @@
*
* @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 f89e52d..141dc79 100644
--- a/core/java/com/android/internal/policy/PhoneWindow.java
+++ b/core/java/com/android/internal/policy/PhoneWindow.java
@@ -3140,6 +3140,7 @@
// 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 cc4f559..26915bc 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 @@
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 @@
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 @@
// 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 @@
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 @@
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 @@
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 @@
} 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 @@
}
}
- private void handleLongPressOnHome(int deviceId) {
+ private void handleLongPressOnHome(int deviceId, long eventTime) {
if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_NOTHING) {
return;
}
@@ -1648,7 +1651,7 @@
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 @@
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 @@
// 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 @@
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();
}