Allow IVoiceInteractionSessionListener to listen for window vis changes

- The listener currently tracks session shown/hidden, but doesn't track
  the visibility of the session window which can change on the client
  side without the server knowing. In some cases, it's useful for SysUI
  to be able to track the visibility of the session window to show/hide
  bars appropriately.

Bug: 222308557
Test: Manual, launch the assistant and verify the calls are made
Change-Id: I9b4bb27c9497b2a828616caf72eaf345b072c294
This commit is contained in:
Winson Chung
2022-03-11 08:17:05 +00:00
committed by Ahaan Ugale
parent 5aa7a6bda6
commit 06fb230d6d
5 changed files with 62 additions and 2 deletions

View File

@@ -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();
}

View File

@@ -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);
}

View File

@@ -29,6 +29,11 @@
*/
void onVoiceSessionHidden();
/**
* Called when a voice session window is shown/hidden.
*/
void onVoiceSessionWindowVisibilityChanged(boolean visible);
/**
* Called when UI hints were received.
*/

View File

@@ -186,6 +186,14 @@ public class AssistManager {
AssistantSessionEvent.ASSISTANT_SESSION_CLOSE);
}
@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) {

View File

@@ -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;