Pass an args bundle to launchAssistAction.
In order to track the input device that was used to trigger assist, the
input device id is sent as an extra in the assist intent whenever it is
available. This is particularly useful on TVs, when an app may want to
know whether the input device has a microphone.
Bug: 21666123
Change-Id: I0f8c09e2f617606bef481bdff924cb6b9b47dd12
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 64e30e5..d0b3671 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -10643,7 +10643,7 @@
@Override
public Bundle getAssistContextExtras(int requestType) {
PendingAssistExtras pae = enqueueAssistContext(requestType, null, null, null,
- UserHandle.getCallingUserId(), PENDING_ASSIST_EXTRAS_TIMEOUT);
+ UserHandle.getCallingUserId(), null, PENDING_ASSIST_EXTRAS_TIMEOUT);
if (pae == null) {
return null;
}
@@ -10666,11 +10666,11 @@
@Override
public void requestAssistContextExtras(int requestType, IResultReceiver receiver) {
enqueueAssistContext(requestType, null, null, receiver, UserHandle.getCallingUserId(),
- PENDING_ASSIST_EXTRAS_LONG_TIMEOUT);
+ null, PENDING_ASSIST_EXTRAS_LONG_TIMEOUT);
}
private PendingAssistExtras enqueueAssistContext(int requestType, Intent intent, String hint,
- IResultReceiver receiver, int userHandle, long timeout) {
+ IResultReceiver receiver, int userHandle, Bundle args, long timeout) {
enforceCallingPermission(android.Manifest.permission.GET_TOP_ACTIVITY_INFO,
"enqueueAssistContext()");
synchronized (this) {
@@ -10689,6 +10689,9 @@
}
PendingAssistExtras pae;
Bundle extras = new Bundle();
+ if (args != null) {
+ extras.putAll(args);
+ }
extras.putString(Intent.EXTRA_ASSIST_PACKAGE, activity.packageName);
extras.putInt(Intent.EXTRA_ASSIST_UID, activity.app.uid);
pae = new PendingAssistExtras(activity, extras, intent, hint, receiver, userHandle);
@@ -10774,8 +10777,9 @@
}
}
- public boolean launchAssistIntent(Intent intent, int requestType, String hint, int userHandle) {
- return enqueueAssistContext(requestType, intent, hint, null, userHandle,
+ public boolean launchAssistIntent(Intent intent, int requestType, String hint, int userHandle,
+ Bundle args) {
+ return enqueueAssistContext(requestType, intent, hint, null, userHandle, args,
PENDING_ASSIST_EXTRAS_TIMEOUT) != null;
}
diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java
index 46793b9..b668bba 100644
--- a/services/core/java/com/android/server/policy/PhoneWindowManager.java
+++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java
@@ -1204,7 +1204,7 @@
launchHomeFromHotKey();
}
- private void handleLongPressOnHome() {
+ private void handleLongPressOnHome(int deviceId) {
if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
mHomeConsumed = true;
performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
@@ -1212,7 +1212,7 @@
if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
toggleRecentApps();
} else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
- launchAssistAction();
+ launchAssistAction(null, deviceId);
}
}
}
@@ -2637,7 +2637,7 @@
}
} else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
if (!keyguardOn) {
- handleLongPressOnHome();
+ handleLongPressOnHome(event.getDeviceId());
}
}
return -1;
@@ -2717,7 +2717,7 @@
mAssistKeyLongPressed = false;
} else {
if (!keyguardOn) {
- launchAssistAction();
+ launchAssistAction(null, event.getDeviceId());
}
}
}
@@ -2779,7 +2779,7 @@
if (down) {
mPendingMetaAction = true;
} else if (mPendingMetaAction) {
- launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD);
+ launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId());
}
return -1;
}
@@ -3000,26 +3000,22 @@
}
private void launchAssistAction() {
- launchAssistAction(null);
+ launchAssistAction(null, Integer.MIN_VALUE);
}
private void launchAssistAction(String hint) {
+ launchAssistAction(hint, Integer.MIN_VALUE);
+ }
+
+ private void launchAssistAction(String hint, int deviceId) {
sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
- Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
- .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
- if (intent != null) {
- if (hint != null) {
- intent.putExtra(hint, true);
- }
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
- | Intent.FLAG_ACTIVITY_SINGLE_TOP
- | Intent.FLAG_ACTIVITY_CLEAR_TOP);
- try {
- startActivityAsUser(intent, UserHandle.CURRENT);
- } catch (ActivityNotFoundException e) {
- Slog.w(TAG, "No activity to handle assist action.", e);
- }
+ Bundle args = null;
+ if (deviceId > Integer.MIN_VALUE) {
+ args = new Bundle();
+ args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId);
}
+ ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
+ .launchAssistAction(hint, UserHandle.myUserId(), args);
}
private void startActivityAsUser(Intent intent, UserHandle handle) {
diff --git a/services/core/java/com/android/server/search/SearchManagerService.java b/services/core/java/com/android/server/search/SearchManagerService.java
index 2b2b2ac..dd2286f 100644
--- a/services/core/java/com/android/server/search/SearchManagerService.java
+++ b/services/core/java/com/android/server/search/SearchManagerService.java
@@ -34,6 +34,7 @@
import android.content.pm.ResolveInfo;
import android.database.ContentObserver;
import android.os.Binder;
+import android.os.Bundle;
import android.os.Process;
import android.os.RemoteException;
import android.os.UserHandle;
@@ -264,7 +265,7 @@
}
@Override
- public boolean launchAssistAction(String hint, int userHandle) {
+ public boolean launchAssistAction(String hint, int userHandle, Bundle args) {
ComponentName comp = getAssistIntent(userHandle);
if (comp == null) {
return false;
@@ -275,7 +276,7 @@
intent.setComponent(comp);
IActivityManager am = ActivityManagerNative.getDefault();
return am.launchAssistIntent(intent, ActivityManager.ASSIST_CONTEXT_BASIC, hint,
- userHandle);
+ userHandle, args);
} catch (RemoteException e) {
} finally {
Binder.restoreCallingIdentity(ident);