diff options
| author | 2022-04-27 17:44:18 +0000 | |
|---|---|---|
| committer | 2022-04-27 17:44:18 +0000 | |
| commit | 26b037f44a7a25ea4d6f050b0dfa57d8d6482b48 (patch) | |
| tree | 51aa884ed13e3b528a71aed1feb7665d9659ee6e | |
| parent | f75d1d67f571fddf693bfe8fdbdbf0eb07c229e5 (diff) | |
| parent | ad3eae01cf59f8fd7491a9c16ad67df000efc547 (diff) | |
Merge "Allow IVoiceInteractionSessionListener to listen for window vis changes" into tm-dev am: 44e14e72b6 am: ad3eae01cf
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17211290
Change-Id: Ifa819a0d6d554dd2d6f0a4c8f490e237b0146156
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
5 files changed, 62 insertions, 2 deletions
diff --git a/core/java/android/service/voice/VoiceInteractionSession.java b/core/java/android/service/voice/VoiceInteractionSession.java index 4bbfbc2e717d..b783f6b8fd51 100644 --- a/core/java/android/service/voice/VoiceInteractionSession.java +++ b/core/java/android/service/voice/VoiceInteractionSession.java @@ -1095,7 +1095,7 @@ public class VoiceInteractionSession implements KeyEvent.Callback, ComponentCall if (!mWindowVisible) { mWindowVisible = true; if (mUiEnabled) { - mWindow.show(); + showWindow(); } } if (showCallback != null) { @@ -1284,9 +1284,25 @@ public class VoiceInteractionSession implements KeyEvent.Callback, ComponentCall } } + void showWindow() { + if (mWindow != null) { + mWindow.show(); + try { + mSystemService.setSessionWindowVisible(mToken, true); + } catch (RemoteException e) { + Log.w(TAG, "Failed to notify session window shown", e); + } + } + } + void ensureWindowHidden() { if (mWindow != null) { mWindow.hide(); + try { + mSystemService.setSessionWindowVisible(mToken, false); + } catch (RemoteException e) { + Log.w(TAG, "Failed to notify session window hidden", e); + } } } @@ -1377,7 +1393,7 @@ public class VoiceInteractionSession implements KeyEvent.Callback, ComponentCall if (mWindowVisible) { if (enabled) { ensureWindowAdded(); - mWindow.show(); + showWindow(); } else { ensureWindowHidden(); } diff --git a/core/java/com/android/internal/app/IVoiceInteractionManagerService.aidl b/core/java/com/android/internal/app/IVoiceInteractionManagerService.aidl index 52d54cd1f717..681693b1dbad 100644 --- a/core/java/com/android/internal/app/IVoiceInteractionManagerService.aidl +++ b/core/java/com/android/internal/app/IVoiceInteractionManagerService.aidl @@ -284,4 +284,9 @@ interface IVoiceInteractionManagerService { * Stops to listen the status of visible activity. */ void stopListeningVisibleActivityChanged(in IBinder token); + + /** + * Notifies when the session window is shown or hidden. + */ + void setSessionWindowVisible(in IBinder token, boolean visible); } diff --git a/core/java/com/android/internal/app/IVoiceInteractionSessionListener.aidl b/core/java/com/android/internal/app/IVoiceInteractionSessionListener.aidl index bc757e24c852..6e409885fa13 100644 --- a/core/java/com/android/internal/app/IVoiceInteractionSessionListener.aidl +++ b/core/java/com/android/internal/app/IVoiceInteractionSessionListener.aidl @@ -30,6 +30,11 @@ void onVoiceSessionHidden(); /** + * Called when a voice session window is shown/hidden. + */ + void onVoiceSessionWindowVisibilityChanged(boolean visible); + + /** * Called when UI hints were received. */ void onSetUiHints(in Bundle args); diff --git a/packages/SystemUI/src/com/android/systemui/assist/AssistManager.java b/packages/SystemUI/src/com/android/systemui/assist/AssistManager.java index 9d5b93c2b329..7c2673c31bf5 100644 --- a/packages/SystemUI/src/com/android/systemui/assist/AssistManager.java +++ b/packages/SystemUI/src/com/android/systemui/assist/AssistManager.java @@ -187,6 +187,14 @@ public class AssistManager { } @Override + public void onVoiceSessionWindowVisibilityChanged(boolean visible) + throws RemoteException { + if (VERBOSE) { + Log.v(TAG, "Window visibility changed: " + visible); + } + } + + @Override public void onSetUiHints(Bundle hints) { if (VERBOSE) { Log.v(TAG, "UI hints received"); diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java index 8cbbe947d32d..f31cdcba5830 100644 --- a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java +++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java @@ -1824,6 +1824,32 @@ public class VoiceInteractionManagerService extends SystemService { } } + public void setSessionWindowVisible(IBinder token, boolean visible) { + synchronized (this) { + if (mImpl == null) { + Slog.w(TAG, "setSessionWindowVisible called without running voice interaction " + + "service"); + return; + } + if (mImpl.mActiveSession == null || token != mImpl.mActiveSession.mToken) { + Slog.w(TAG, "setSessionWindowVisible does not match active session"); + return; + } + final long caller = Binder.clearCallingIdentity(); + try { + mVoiceInteractionSessionListeners.broadcast(listener -> { + try { + listener.onVoiceSessionWindowVisibilityChanged(visible); + } catch (RemoteException e) { + Slog.e(TAG, "Error delivering window visibility event to listener.", e); + } + }); + } finally { + Binder.restoreCallingIdentity(caller); + } + } + } + @Override public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return; |