List<ResolveInfo> getGlobalSearchActivities();
ComponentName getGlobalSearchActivity();
ComponentName getWebSearchActivity();
- ComponentName getAssistIntent(int userHandle);
- boolean launchAssistAction(String hint, int userHandle, in Bundle args);
+ void launchAssist(in Bundle args);
+ boolean launchLegacyAssist(String hint, int userHandle, in Bundle args);
}
*
* @hide
*/
- public Intent getAssistIntent(Context context, boolean inclContext) {
- return getAssistIntent(context, inclContext, UserHandle.myUserId());
- }
-
- /**
- * Gets an intent for launching installed assistant activity, or null if not available.
- * @return The assist intent.
- *
- * @hide
- */
- public Intent getAssistIntent(Context context, boolean inclContext, int userHandle) {
+ public Intent getAssistIntent(boolean inclContext) {
try {
- if (mService == null) {
- return null;
- }
- ComponentName comp = mService.getAssistIntent(userHandle);
- if (comp == null) {
- return null;
- }
Intent intent = new Intent(Intent.ACTION_ASSIST);
- intent.setComponent(comp);
if (inclContext) {
IActivityManager am = ActivityManagerNative.getDefault();
Bundle extras = am.getAssistContextExtras(ActivityManager.ASSIST_CONTEXT_BASIC);
}
/**
- * Launch an assist action for the current top activity.
+ * Starts the assistant.
+ *
+ * @param args the args to pass to the assistant
+ *
+ * @hide
+ */
+ public void launchAssist(Bundle args) {
+ try {
+ if (mService == null) {
+ return;
+ }
+ mService.launchAssist(args);
+ } catch (RemoteException re) {
+ Log.e(TAG, "launchAssist() failed: " + re);
+ }
+ }
+
+ /**
+ * Starts the legacy assistant (i.e. the {@link Intent#ACTION_ASSIST}).
+ *
+ * @param args the args to pass to the assistant
+ *
* @hide
*/
- public boolean launchAssistAction(String hint, int userHandle, Bundle args) {
+ public boolean launchLegacyAssist(String hint, int userHandle, Bundle args) {
try {
if (mService == null) {
return false;
}
- return mService.launchAssistAction(hint, userHandle, args);
+ return mService.launchLegacyAssist(hint, userHandle, args);
} catch (RemoteException re) {
- Log.e(TAG, "launchAssistAction() failed: " + re);
+ Log.e(TAG, "launchAssist() failed: " + re);
return false;
}
}
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.os.Bundle;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.provider.Settings;
ServiceManager.getService(Context.VOICE_INTERACTION_MANAGER_SERVICE));
}
- public void showSessionForActiveService(IVoiceInteractionSessionShowCallback showCallback) {
+ public void showSessionForActiveService(Bundle args,
+ IVoiceInteractionSessionShowCallback showCallback) {
try {
- mVoiceInteractionManagerService.showSessionForActiveService(showCallback);
+ mVoiceInteractionManagerService.showSessionForActiveService(args, showCallback);
} catch (RemoteException e) {
Log.w(TAG, "Failed to call showSessionForActiveService", e);
}
}
Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
- .getAssistIntent(mContext, false, userId);
- if (intent != null) {
- return intent.getComponent();
+ .getAssistIntent(false);
+ PackageManager pm = mContext.getPackageManager();
+ ResolveInfo info = pm.resolveActivityAsUser(intent, PackageManager.MATCH_DEFAULT_ONLY,
+ userId);
+ if (info != null) {
+ return new ComponentName(info.activityInfo.applicationInfo.packageName,
+ info.activityInfo.name);
}
-
return null;
}
* Shows the session for the currently active service. Used to start a new session from system
* affordances.
*
+ * @param args the bundle to pass as arguments to the voice interaction session
* @param showCallback callback to be notified when the session was shown
*/
- void showSessionForActiveService(IVoiceInteractionSessionShowCallback showCallback);
+ void showSessionForActiveService(in Bundle args,
+ IVoiceInteractionSessionShowCallback showCallback);
/**
* Hides the session from the active service, if it is showing.
Bundle args = new Bundle();
args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, event.getDeviceId());
return ((SearchManager)getContext().getSystemService(Context.SEARCH_SERVICE))
- .launchAssistAction(null, UserHandle.myUserId(), args);
+ .launchLegacyAssist(null, UserHandle.myUserId(), args);
}
return result;
}
package com.android.internal.statusbar;
-import com.android.internal.statusbar.StatusBarIcon;
+import android.os.Bundle;
import android.service.notification.StatusBarNotification;
+import com.android.internal.statusbar.StatusBarIcon;
+
/** @hide */
oneway interface IStatusBar
{
void appTransitionStarting(long statusBarAnimationsStartTime, long statusBarAnimationsDuration);
void showAssistDisclosure();
+ void startAssist(in Bundle args);
}
package com.android.internal.statusbar;
+import android.os.Bundle;
+import android.service.notification.StatusBarNotification;
+
import com.android.internal.statusbar.IStatusBar;
import com.android.internal.statusbar.StatusBarIcon;
import com.android.internal.statusbar.StatusBarIconList;
import com.android.internal.statusbar.NotificationVisibility;
-import android.service.notification.StatusBarNotification;
/** @hide */
interface IStatusBarService
* bar caused by this app transition in millis
*/
void appTransitionStarting(long statusBarAnimationsStartTime, long statusBarAnimationsDuration);
+
+ void startAssist(in Bundle args);
}
import com.android.internal.app.AssistUtils;
import com.android.internal.app.IVoiceInteractionSessionShowCallback;
import com.android.systemui.R;
+import com.android.systemui.statusbar.BaseStatusBar;
import com.android.systemui.statusbar.CommandQueue;
import com.android.systemui.statusbar.phone.PhoneStatusBar;
private static final String ASSIST_ICON_METADATA_NAME =
"com.android.systemui.action_assist_icon";
- private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
- .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
- .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
- .build();
-
private static final long TIMEOUT_SERVICE = 2500;
private static final long TIMEOUT_ACTIVITY = 1000;
private final AssistDisclosure mAssistDisclosure;
private AssistOrbContainer mView;
- private final PhoneStatusBar mBar;
+ private final BaseStatusBar mBar;
private final AssistUtils mAssistUtils;
private ComponentName mAssistComponent;
}
};
- public AssistManager(PhoneStatusBar bar, Context context) {
+ public AssistManager(BaseStatusBar bar, Context context) {
mContext = context;
mBar = bar;
mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
}
}
- public void onGestureInvoked() {
+ public void startAssist(Bundle args) {
+ updateAssistInfo();
if (mAssistComponent == null) {
return;
}
? TIMEOUT_SERVICE
: TIMEOUT_ACTIVITY);
}
- startAssist();
+ startAssistInternal(args);
}
public void hideAssist() {
mView.show(true /* show */, true /* animate */);
}
- private void startAssist() {
+ private void startAssistInternal(Bundle args) {
if (mAssistComponent != null) {
if (isAssistantService()) {
- startVoiceInteractor();
+ startVoiceInteractor(args);
} else {
- startAssistActivity();
+ startAssistActivity(args);
}
}
}
- private void startAssistActivity() {
+ private void startAssistActivity(Bundle args) {
if (!mBar.isDeviceProvisioned()) {
return;
}
Settings.Secure.ASSIST_STRUCTURE_ENABLED, 1, UserHandle.USER_CURRENT) != 0;
final Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
- .getAssistIntent(mContext, structureEnabled, UserHandle.USER_CURRENT);
+ .getAssistIntent(structureEnabled);
if (intent == null) {
return;
}
if (mAssistComponent != null) {
intent.setComponent(mAssistComponent);
}
+ intent.putExtras(args);
if (structureEnabled) {
showDisclosure();
}
}
- private void startVoiceInteractor() {
- mAssistUtils.showSessionForActiveService(mShowCallback);
+ private void startVoiceInteractor(Bundle args) {
+ mAssistUtils.showSessionForActiveService(args, mShowCallback);
}
public void launchVoiceAssistFromKeyguard() {
public void onUserSwitched(int newUserId) {
updateAssistInfo();
}
-
- public void prepareBeforeInvocation() {
- updateAssistInfo();
- }
}
import android.os.RemoteException;
import android.os.SystemProperties;
import android.os.UserHandle;
+import android.os.UserManager;
import android.provider.Settings;
import android.util.Log;
import android.util.MutableBoolean;
import android.view.SurfaceControl;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityManager;
+
+import com.android.internal.app.AssistUtils;
import com.android.systemui.Prefs;
import com.android.systemui.R;
import com.android.systemui.recents.Constants;
AppWidgetManager mAwm;
PackageManager mPm;
IPackageManager mIpm;
- SearchManager mSm;
+ AssistUtils mAssistUtils;
WindowManager mWm;
Display mDisplay;
String mRecentsPackage;
mAwm = AppWidgetManager.getInstance(context);
mPm = context.getPackageManager();
mIpm = AppGlobals.getPackageManager();
- mSm = (SearchManager) context.getSystemService(Context.SEARCH_SERVICE);
+ mAssistUtils = new AssistUtils(context);
mWm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
mDisplay = mWm.getDefaultDisplay();
mRecentsPackage = context.getPackageName();
mBgProtectionCanvas = new Canvas();
// Resolve the assist intent
- Intent assist = mSm.getAssistIntent(context, false);
- if (assist != null) {
- mAssistComponent = assist.getComponent();
- }
+ mAssistComponent = mAssistUtils.getAssistComponentForUser(UserHandle.myUserId());
if (Constants.DebugFlags.App.EnableSystemServicesProxy) {
// Create a dummy icon
* Returns the first Recents widget from the same package as the global assist activity.
*/
private AppWidgetProviderInfo resolveSearchAppWidget() {
+ if (mAssistComponent == null) return null;
List<AppWidgetProviderInfo> widgets = mAwm.getInstalledProviders(
AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX);
for (AppWidgetProviderInfo info : widgets) {
import android.database.ContentObserver;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
-import android.graphics.drawable.Icon;
import android.os.AsyncTask;
import android.os.Build;
+import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.util.SparseArray;
import android.util.SparseBooleanArray;
import android.view.Display;
-import android.view.Gravity;
import android.view.IWindowManager;
import android.view.LayoutInflater;
import android.view.MotionEvent;
mAssistManager.showDisclosure();
}
}
+
+ @Override
+ public void startAssist(Bundle args) {
+ if (mAssistManager != null) {
+ mAssistManager.startAssist(args);
+ }
+ }
}
package com.android.systemui.statusbar;
+import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
private static final int MSG_APP_TRANSITION_CANCELLED = 20 << MSG_SHIFT;
private static final int MSG_APP_TRANSITION_STARTING = 21 << MSG_SHIFT;
private static final int MSG_ASSIST_DISCLOSURE = 22 << MSG_SHIFT;
+ private static final int MSG_START_ASSIST = 23 << MSG_SHIFT;
public static final int FLAG_EXCLUDE_NONE = 0;
public static final int FLAG_EXCLUDE_SEARCH_PANEL = 1 << 0;
public void appTransitionCancelled();
public void appTransitionStarting(long startTime, long duration);
public void showAssistDisclosure();
+ public void startAssist(Bundle args);
}
public CommandQueue(Callbacks callbacks, StatusBarIconList list) {
}
}
+ public void startAssist(Bundle args) {
+ synchronized (mList) {
+ mHandler.removeMessages(MSG_START_ASSIST);
+ mHandler.obtainMessage(MSG_START_ASSIST, args).sendToTarget();
+ }
+ }
+
private final class H extends Handler {
public void handleMessage(Message msg) {
final int what = msg.what & MSG_MASK;
case MSG_ASSIST_DISCLOSURE:
mCallbacks.showAssistDisclosure();
break;
+ case MSG_START_ASSIST:
+ mCallbacks.startAssist((Bundle) msg.obj);
+ break;
}
}
}
import android.view.ThreadedRenderer;
import android.view.VelocityTracker;
import android.view.View;
-import android.view.ViewConfiguration;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewStub;
import android.view.WindowManager;
import com.android.systemui.EventLogTags;
import com.android.systemui.Prefs;
import com.android.systemui.R;
-import com.android.systemui.SwipeHelper;
import com.android.systemui.assist.AssistManager;
import com.android.systemui.doze.DozeHost;
import com.android.systemui.doze.DozeLog;
if (shouldDisableNavbarGestures()) {
return false;
}
- mAssistManager.prepareBeforeInvocation();
- mAssistManager.onGestureInvoked();
+ mAssistManager.startAssist(new Bundle() /* args */);
awakenDreams();
if (mNavigationBarView != null) {
mNavigationBarView.abortCurrentGesture();
}
}
- private void launchAssistAction() {
- 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);
Bundle args = null;
args = new Bundle();
args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId);
}
- ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
- .launchAssistAction(hint, UserHandle.myUserId(), args);
+ if ((mContext.getResources().getConfiguration().uiMode
+ & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_TELEVISION) {
+ // On TV, use legacy handling until assistants are implemented in the proper way.
+ ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
+ .launchLegacyAssist(hint, UserHandle.myUserId(), args);
+ } else {
+ try {
+ if (hint != null) {
+ if (args == null) {
+ args = new Bundle();
+ }
+ args.putBoolean(hint, true);
+ }
+ IStatusBarService statusbar = getStatusBarService();
+ if (statusbar != null) {
+ statusbar.startAssist(args);
+ }
+ } catch (RemoteException e) {
+ Slog.e(TAG, "RemoteException when starting assist", e);
+ // re-acquire status bar service next time it is needed.
+ mStatusBarService = null;
+ }
+ }
}
private void startActivityAsUser(Intent intent, UserHandle handle) {
import com.android.internal.content.PackageMonitor;
import com.android.internal.util.IndentingPrintWriter;
+import com.android.server.LocalServices;
+import com.android.server.statusbar.StatusBarManagerInternal;
import java.io.FileDescriptor;
import java.io.PrintWriter;
}
@Override
- public ComponentName getAssistIntent(int userHandle) {
+ public void launchAssist(Bundle args) {
+ StatusBarManagerInternal statusBarManager =
+ LocalServices.getService(StatusBarManagerInternal.class);
+ if (statusBarManager != null) {
+ statusBarManager.startAssist(args);
+ }
+ }
+
+ private ComponentName getLegacyAssistComponent(int userHandle) {
try {
userHandle = ActivityManager.handleIncomingUser(Binder.getCallingPid(),
- Binder.getCallingUid(), userHandle, true, false, "getAssistIntent", null);
+ Binder.getCallingUid(), userHandle, true, false, "getLegacyAssistComponent", null);
IPackageManager pm = AppGlobals.getPackageManager();
Intent assistIntent = new Intent(Intent.ACTION_ASSIST);
ResolveInfo info =
pm.resolveIntent(assistIntent,
- assistIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
- PackageManager.MATCH_DEFAULT_ONLY, userHandle);
+ assistIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
+ PackageManager.MATCH_DEFAULT_ONLY, userHandle);
if (info != null) {
return new ComponentName(
info.activityInfo.applicationInfo.packageName,
}
} catch (RemoteException re) {
// Local call
- Log.e(TAG, "RemoteException in getAssistIntent: " + re);
+ Log.e(TAG, "RemoteException in getLegacyAssistComponent: " + re);
} catch (Exception e) {
- Log.e(TAG, "Exception in getAssistIntent: " + e);
+ Log.e(TAG, "Exception in getLegacyAssistComponent: " + e);
}
return null;
}
@Override
- public boolean launchAssistAction(String hint, int userHandle, Bundle args) {
- ComponentName comp = getAssistIntent(userHandle);
+ public boolean launchLegacyAssist(String hint, int userHandle, Bundle args) {
+ ComponentName comp = getLegacyAssistComponent(userHandle);
if (comp == null) {
return false;
}
package com.android.server.statusbar;
+import android.os.Bundle;
+
import com.android.server.notification.NotificationDelegate;
public interface StatusBarManagerInternal {
void notificationLightOff();
void showScreenPinningRequest();
void showAssistDisclosure();
+ void startAssist(Bundle args);
}
import android.app.StatusBarManager;
import android.os.Binder;
+import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.RemoteException;
}
}
}
+
+ @Override
+ public void startAssist(Bundle args) {
+ if (mBar != null) {
+ try {
+ mBar.startAssist(args);
+ } catch (RemoteException e) {
+ }
+ }
+ }
};
// ================================================================================
}
}
+ @Override
+ public void startAssist(Bundle args) {
+ if (mBar != null) {
+ try {
+ mBar.startAssist(args);
+ } catch (RemoteException ex) {}
+ }
+ }
+
private void enforceStatusBar() {
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR,
"StatusBarManagerService");
}
@Override
- public void showSessionForActiveService(IVoiceInteractionSessionShowCallback showCallback) {
+ public void showSessionForActiveService(Bundle args,
+ IVoiceInteractionSessionShowCallback showCallback) {
enforceCallingPermission(Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE);
synchronized (this) {
if (mImpl == null) {
}
final long caller = Binder.clearCallingIdentity();
try {
- mImpl.showSessionLocked(new Bundle() /* sessionArgs */,
+ mImpl.showSessionLocked(args,
VoiceInteractionSession.SHOW_SOURCE_ASSIST_GESTURE
| VoiceInteractionSession.SHOW_WITH_ASSIST
| VoiceInteractionSession.SHOW_WITH_SCREENSHOT,