diff --git a/core/api/current.txt b/core/api/current.txt index 2968b59e16c91..1aad4b72b10ad 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -41246,6 +41246,7 @@ package android.service.voice { method public void setUiEnabled(boolean); method public void show(android.os.Bundle, int); method public void startAssistantActivity(android.content.Intent); + method public void startAssistantActivity(@NonNull android.content.Intent, @NonNull android.os.Bundle); method public void startVoiceActivity(android.content.Intent); method public final void unregisterVisibleActivityCallback(@NonNull android.service.voice.VoiceInteractionSession.VisibleActivityCallback); field public static final String KEY_SHOW_SESSION_ID = "android.service.voice.SHOW_SESSION_ID"; diff --git a/core/java/android/service/voice/VoiceInteractionSession.java b/core/java/android/service/voice/VoiceInteractionSession.java index 5778518921ca5..cabcae30851f8 100644 --- a/core/java/android/service/voice/VoiceInteractionSession.java +++ b/core/java/android/service/voice/VoiceInteractionSession.java @@ -26,6 +26,7 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.TestApi; import android.app.Activity; +import android.app.ActivityOptions; import android.app.Dialog; import android.app.DirectAction; import android.app.Instrumentation; @@ -1527,8 +1528,34 @@ public class VoiceInteractionSession implements KeyEvent.Callback, ComponentCall *

By default, the system will create a window for the UI for this session. If you are using * an assistant activity instead, then you can disable the window creation by calling * {@link #setUiEnabled} in {@link #onPrepareShow(Bundle, int)}.

+ * + * NOTE: if the app would like to override some options to start the Activity, + * use {@link #startAssistantActivity(Intent, Bundle)} instead. */ public void startAssistantActivity(Intent intent) { + startAssistantActivity(intent, ActivityOptions.makeBasic().toBundle()); + } + + /** + *

Ask that a new assistant activity be started. This will create a new task in the + * in activity manager: this means that + * {@link Intent#FLAG_ACTIVITY_NEW_TASK Intent.FLAG_ACTIVITY_NEW_TASK} + * will be set for you to make it a new task.

+ * + *

The newly started activity will be displayed on top of other activities in the system + * in a new layer that is not affected by multi-window mode. Tasks started from this activity + * will go into the normal activity layer and not this new layer.

+ * + *

By default, the system will create a window for the UI for this session. If you are using + * an assistant activity instead, then you can disable the window creation by calling + * {@link #setUiEnabled} in {@link #onPrepareShow(Bundle, int)}.

+ * + * @param intent the intent used to start an assistant activity + * @param bundle Additional options for how the Activity should be started. See + * {@link ActivityOptions} for how to build the Bundle supplied here. + */ + public void startAssistantActivity(@NonNull Intent intent, @NonNull Bundle bundle) { + Objects.requireNonNull(bundle); if (mToken == null) { throw new IllegalStateException("Can't call before onCreate()"); } @@ -1537,7 +1564,7 @@ public class VoiceInteractionSession implements KeyEvent.Callback, ComponentCall intent.prepareToLeaveProcess(mContext); int res = mSystemService.startAssistantActivity(mToken, intent, intent.resolveType(mContext.getContentResolver()), - mContext.getAttributionTag()); + mContext.getAttributionTag(), bundle); Instrumentation.checkStartActivityResult(res, intent); } catch (RemoteException e) { } diff --git a/core/java/com/android/internal/app/IVoiceInteractionManagerService.aidl b/core/java/com/android/internal/app/IVoiceInteractionManagerService.aidl index 5eb97862c79f5..6b40d9873fbb5 100644 --- a/core/java/com/android/internal/app/IVoiceInteractionManagerService.aidl +++ b/core/java/com/android/internal/app/IVoiceInteractionManagerService.aidl @@ -51,7 +51,7 @@ interface IVoiceInteractionManagerService { int startVoiceActivity(IBinder token, in Intent intent, String resolvedType, String attributionTag); int startAssistantActivity(IBinder token, in Intent intent, String resolvedType, - String attributionTag); + String attributionTag, in Bundle bundle); void setKeepAwake(IBinder token, boolean keepAwake); void closeSystemDialogs(IBinder token); void finish(IBinder token); diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java index d4374a9c26544..fd542939373ba 100644 --- a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java +++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java @@ -1049,7 +1049,8 @@ public class VoiceInteractionManagerService extends SystemService { @Override public int startAssistantActivity(@NonNull IBinder token, @NonNull Intent intent, - @Nullable String resolvedType, @Nullable String attributionTag) { + @Nullable String resolvedType, @NonNull String attributionTag, + @NonNull Bundle bundle) { synchronized (this) { if (mImpl == null) { Slog.w(TAG, "startAssistantActivity without running voice interaction service"); @@ -1060,7 +1061,7 @@ public class VoiceInteractionManagerService extends SystemService { final long caller = Binder.clearCallingIdentity(); try { return mImpl.startAssistantActivityLocked(attributionTag, callingPid, - callingUid, token, intent, resolvedType); + callingUid, token, intent, resolvedType, bundle); } finally { Binder.restoreCallingIdentity(caller); } diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java index ad0e9217c50b4..96b69f8c4130c 100644 --- a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java +++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java @@ -29,7 +29,6 @@ import android.Manifest; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.ActivityManager; -import android.app.ActivityOptions; import android.app.ActivityTaskManager; import android.app.AppGlobals; import android.app.ApplicationExitInfo; @@ -376,7 +375,8 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne @GuardedBy("this") public int startAssistantActivityLocked(@Nullable String callingFeatureId, int callingPid, - int callingUid, IBinder token, Intent intent, String resolvedType) { + int callingUid, IBinder token, Intent intent, String resolvedType, + @NonNull Bundle bundle) { try { if (mActiveSession == null || token != mActiveSession.mToken) { Slog.w(TAG, "startAssistantActivity does not match active session"); @@ -388,10 +388,10 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne } intent = new Intent(intent); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - final ActivityOptions options = ActivityOptions.makeBasic(); - options.setLaunchActivityType(ACTIVITY_TYPE_ASSISTANT); + // TODO: make the key public hidden + bundle.putInt("android.activity.activityType", ACTIVITY_TYPE_ASSISTANT); return mAtm.startAssistantActivity(mComponent.getPackageName(), callingFeatureId, - callingPid, callingUid, intent, resolvedType, options.toBundle(), mUser); + callingPid, callingUid, intent, resolvedType, bundle, mUser); } catch (RemoteException e) { throw new IllegalStateException("Unexpected remote error", e); }