diff options
6 files changed, 61 insertions, 11 deletions
diff --git a/core/api/current.txt b/core/api/current.txt index bec2559bb461..4b1335e0d6d6 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -40530,11 +40530,12 @@ package android.service.voice { method public void onLaunchVoiceAssistFromKeyguard(); method public void onPrepareToShowSession(@NonNull android.os.Bundle, int); method public void onReady(); - method public void onShowSessionFailed(); + method public void onShowSessionFailed(@NonNull android.os.Bundle); method public void onShutdown(); method public void setDisabledShowContext(int); method public final void setUiHints(@NonNull android.os.Bundle); method public void showSession(android.os.Bundle, int); + field public static final String KEY_SHOW_SESSION_ID = "android.service.voice.SHOW_SESSION_ID"; field public static final String SERVICE_INTERFACE = "android.service.voice.VoiceInteractionService"; field public static final String SERVICE_META_DATA = "android.voice_interaction"; } diff --git a/core/java/android/service/voice/IVoiceInteractionService.aidl b/core/java/android/service/voice/IVoiceInteractionService.aidl index efae5c1569a7..6a5460605f32 100644 --- a/core/java/android/service/voice/IVoiceInteractionService.aidl +++ b/core/java/android/service/voice/IVoiceInteractionService.aidl @@ -31,5 +31,5 @@ oneway interface IVoiceInteractionService { void getActiveServiceSupportedActions(in List<String> voiceActions, in IVoiceActionCheckCallback callback); void prepareToShowSession(in Bundle args, int flags); - void showSessionFailed(); + void showSessionFailed(in Bundle args); } diff --git a/core/java/android/service/voice/VoiceInteractionService.java b/core/java/android/service/voice/VoiceInteractionService.java index a5156ef78e9c..b2f465a6a5dc 100644 --- a/core/java/android/service/voice/VoiceInteractionService.java +++ b/core/java/android/service/voice/VoiceInteractionService.java @@ -95,6 +95,20 @@ public class VoiceInteractionService extends Service { public static final String SERVICE_META_DATA = "android.voice_interaction"; /** + * Bundle key used to specify the id when the system prepares to show session. It increases for + * each request. + * <p> + * Type: int + * </p> + * @see #showSession(Bundle, int) + * @see #onPrepareToShowSession(Bundle, int) + * @see #onShowSessionFailed(Bundle) + * @see VoiceInteractionSession#onShow(Bundle, int) + * @see VoiceInteractionSession#show(Bundle, int) + */ + public static final String KEY_SHOW_SESSION_ID = "android.service.voice.SHOW_SESSION_ID"; + + /** * For apps targeting Build.VERSION_CODES.TRAMISU and above, implementors of this * service can create multiple AlwaysOnHotwordDetector instances in parallel. They will * also e ale to create a single SoftwareHotwordDetector in parallel with any other @@ -170,10 +184,10 @@ public class VoiceInteractionService extends Service { } @Override - public void showSessionFailed() { + public void showSessionFailed(@NonNull Bundle args) { Handler.getMain().executeOrSendMessage(PooledLambda.obtainMessage( VoiceInteractionService::onShowSessionFailed, - VoiceInteractionService.this)); + VoiceInteractionService.this, args)); } }; @@ -205,9 +219,10 @@ public class VoiceInteractionService extends Service { * bind the session service. * * @param args The arguments that were supplied to {@link #showSession(Bundle, int)}. + * It always includes {@link #KEY_SHOW_SESSION_ID}. * @param flags The show flags originally provided to {@link #showSession(Bundle, int)}. * @see #showSession(Bundle, int) - * @see #onShowSessionFailed() + * @see #onShowSessionFailed(Bundle) * @see VoiceInteractionSession#onShow(Bundle, int) * @see VoiceInteractionSession#show(Bundle, int) */ @@ -217,12 +232,14 @@ public class VoiceInteractionService extends Service { /** * Called when the show session failed. E.g. When the system bound the session service failed. * + * @param args Additional info about the show session attempt that failed. For now, includes + * {@link #KEY_SHOW_SESSION_ID}. * @see #showSession(Bundle, int) * @see #onPrepareToShowSession(Bundle, int) * @see VoiceInteractionSession#onShow(Bundle, int) * @see VoiceInteractionSession#show(Bundle, int) */ - public void onShowSessionFailed() { + public void onShowSessionFailed(@NonNull Bundle args) { } /** diff --git a/core/java/android/service/voice/VoiceInteractionSession.java b/core/java/android/service/voice/VoiceInteractionSession.java index 2c702299cf92..d55fedefb5cb 100644 --- a/core/java/android/service/voice/VoiceInteractionSession.java +++ b/core/java/android/service/voice/VoiceInteractionSession.java @@ -1763,7 +1763,8 @@ 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 + * {@link VoiceInteractionService#KEY_SHOW_SESSION_ID}, "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. diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java index 19aa374f96a1..38bf9c298b98 100644 --- a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java +++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java @@ -331,6 +331,12 @@ public class VoiceInteractionManagerService extends SystemService { @GuardedBy("this") private boolean mTemporarilyDisabled; + /** The start value of showSessionId */ + private static final int SHOW_SESSION_START_ID = 0; + + @GuardedBy("this") + private int mShowSessionId = SHOW_SESSION_START_ID; + private final boolean mEnableService; // TODO(b/226201975): remove reference once RoleService supports pre-created users private final RoleObserver mRoleObserver; @@ -350,6 +356,24 @@ public class VoiceInteractionManagerService extends SystemService { } } + int getNextShowSessionId() { + synchronized (this) { + // Reset the showSessionId to SHOW_SESSION_START_ID to avoid the value exceeds + // Integer.MAX_VALUE + if (mShowSessionId == Integer.MAX_VALUE - 1) { + mShowSessionId = SHOW_SESSION_START_ID; + } + mShowSessionId++; + return mShowSessionId; + } + } + + int getShowSessionId() { + synchronized (this) { + return mShowSessionId; + } + } + @Override public @NonNull IVoiceInteractionSoundTriggerSession createSoundTriggerSessionAsOriginator( @NonNull Identity originatorIdentity, IBinder client) { diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java index 4ee33067cc12..857302065f36 100644 --- a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java +++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java @@ -21,6 +21,7 @@ import static android.app.ActivityManager.START_ASSISTANT_NOT_ACTIVE_SESSION; import static android.app.ActivityManager.START_VOICE_HIDDEN_SESSION; import static android.app.ActivityManager.START_VOICE_NOT_ACTIVE_SESSION; import static android.app.WindowConfiguration.ACTIVITY_TYPE_ASSISTANT; +import static android.service.voice.VoiceInteractionService.KEY_SHOW_SESSION_ID; import static com.android.server.policy.PhoneWindowManager.SYSTEM_DIALOG_REASON_ASSIST; @@ -255,13 +256,17 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne /* direct= */ true); } - public boolean showSessionLocked(@NonNull Bundle args, int flags, + public boolean showSessionLocked(@Nullable Bundle args, int flags, @Nullable String attributionTag, @Nullable IVoiceInteractionSessionShowCallback showCallback, @Nullable IBinder activityToken) { + final int sessionId = mServiceStub.getNextShowSessionId(); + final Bundle newArgs = args == null ? new Bundle() : args; + newArgs.putInt(KEY_SHOW_SESSION_ID, sessionId); + try { if (mService != null) { - mService.prepareToShowSession(args, flags); + mService.prepareToShowSession(newArgs, flags); } } catch (RemoteException e) { Slog.w(TAG, "RemoteException while calling prepareToShowSession", e); @@ -275,7 +280,9 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne if (!mActiveSession.mBound) { try { if (mService != null) { - mService.showSessionFailed(); + Bundle failedArgs = new Bundle(); + failedArgs.putInt(KEY_SHOW_SESSION_ID, sessionId); + mService.showSessionFailed(failedArgs); } } catch (RemoteException e) { Slog.w(TAG, "RemoteException while calling showSessionFailed", e); @@ -300,7 +307,7 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne } else { visibleActivities = allVisibleActivities; } - return mActiveSession.showLocked(args, flags, attributionTag, mDisabledShowContext, + return mActiveSession.showLocked(newArgs, flags, attributionTag, mDisabledShowContext, showCallback, visibleActivities); } |