From 32c0da21df172e5557820223ecefd94009325260 Mon Sep 17 00:00:00 2001 From: Ivan Chiang Date: Sat, 7 Jan 2023 08:00:24 +0000 Subject: [PATCH] [VoiceInteraction] Add two callbacks to notify the client side Notify the client side when the system preapres to show session. Notfiy the client side when show session failed Test: atest CtsVoiceInteractionTestCases Bug: 236104300 Change-Id: Iac916cd2b28efbd015245636ec890e054f9f0d00 --- core/api/current.txt | 2 + .../voice/IVoiceInteractionService.aidl | 4 ++ .../voice/VoiceInteractionService.java | 39 +++++++++++++++++++ .../VoiceInteractionManagerServiceImpl.java | 18 +++++++++ 4 files changed, 63 insertions(+) diff --git a/core/api/current.txt b/core/api/current.txt index c147be9b3caf0..5ec28b7283fef 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -40503,7 +40503,9 @@ package android.service.voice { method public android.os.IBinder onBind(android.content.Intent); method @NonNull public java.util.Set onGetSupportedVoiceActions(@NonNull java.util.Set); method public void onLaunchVoiceAssistFromKeyguard(); + method public void onPrepareToShowSession(@NonNull android.os.Bundle, int); method public void onReady(); + method public void onShowSessionFailed(); method public void onShutdown(); method public void setDisabledShowContext(int); method public final void setUiHints(@NonNull android.os.Bundle); diff --git a/core/java/android/service/voice/IVoiceInteractionService.aidl b/core/java/android/service/voice/IVoiceInteractionService.aidl index 24819a6785fb7..efae5c1569a7d 100644 --- a/core/java/android/service/voice/IVoiceInteractionService.aidl +++ b/core/java/android/service/voice/IVoiceInteractionService.aidl @@ -16,6 +16,8 @@ package android.service.voice; +import android.os.Bundle; + import com.android.internal.app.IVoiceActionCheckCallback; /** @@ -28,4 +30,6 @@ oneway interface IVoiceInteractionService { void launchVoiceAssistFromKeyguard(); void getActiveServiceSupportedActions(in List voiceActions, in IVoiceActionCheckCallback callback); + void prepareToShowSession(in Bundle args, int flags); + void showSessionFailed(); } diff --git a/core/java/android/service/voice/VoiceInteractionService.java b/core/java/android/service/voice/VoiceInteractionService.java index 9e1518d899e05..d49b5a5f3c6e6 100644 --- a/core/java/android/service/voice/VoiceInteractionService.java +++ b/core/java/android/service/voice/VoiceInteractionService.java @@ -160,6 +160,20 @@ public class VoiceInteractionService extends Service { voiceActions, callback)); } + + @Override + public void prepareToShowSession(Bundle args, int flags) { + Handler.getMain().executeOrSendMessage(PooledLambda.obtainMessage( + VoiceInteractionService::onPrepareToShowSession, + VoiceInteractionService.this, args, flags)); + } + + @Override + public void showSessionFailed() { + Handler.getMain().executeOrSendMessage(PooledLambda.obtainMessage( + VoiceInteractionService::onShowSessionFailed, + VoiceInteractionService.this)); + } }; IVoiceInteractionManagerService mSystemService; @@ -183,6 +197,31 @@ public class VoiceInteractionService extends Service { public void onLaunchVoiceAssistFromKeyguard() { } + /** + * Notify the interactor when the system prepares to show session. The system is going to + * bind the session service. + * + * @param args The arguments that were supplied to {@link #showSession(Bundle, int)}. + * @param flags The show flags originally provided to {@link #showSession(Bundle, int)}. + * @see #showSession(Bundle, int) + * @see #onShowSessionFailed() + * @see VoiceInteractionSession#onShow(Bundle, int) + * @see VoiceInteractionSession#show(Bundle, int) + */ + public void onPrepareToShowSession(@NonNull Bundle args, int flags) { + } + + /** + * Called when the show session failed. E.g. When the system bound the session service failed. + * + * @see #showSession(Bundle, int) + * @see #onPrepareToShowSession(Bundle, int) + * @see VoiceInteractionSession#onShow(Bundle, int) + * @see VoiceInteractionSession#show(Bundle, int) + */ + public void onShowSessionFailed() { + } + /** * Check whether the given service component is the currently active * VoiceInteractionService. diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java index 9643282718669..13c0f17dbfbb9 100644 --- a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java +++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java @@ -251,11 +251,29 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne @Nullable String attributionTag, @Nullable IVoiceInteractionSessionShowCallback showCallback, @Nullable IBinder activityToken) { + try { + if (mService != null) { + mService.prepareToShowSession(args, flags); + } + } catch (RemoteException e) { + Slog.w(TAG, "RemoteException while calling prepareToShowSession", e); + } + if (mActiveSession == null) { mActiveSession = new VoiceInteractionSessionConnection(mServiceStub, mSessionComponentName, mUser, mContext, this, mInfo.getServiceInfo().applicationInfo.uid, mHandler); } + if (!mActiveSession.mBound) { + try { + if (mService != null) { + mService.showSessionFailed(); + } + } catch (RemoteException e) { + Slog.w(TAG, "RemoteException while calling showSessionFailed", e); + } + } + List allVisibleActivities = LocalServices.getService(ActivityTaskManagerInternal.class) .getTopVisibleActivities();