Loading core/java/android/companion/virtual/computercontrol/ComputerControlSession.java +5 −1 Original line number Diff line number Diff line Loading @@ -140,7 +140,11 @@ public final class ComputerControlSession implements AutoCloseable { /** Called when the session has been successfully created. */ void onSessionCreated(@NonNull ComputerControlSession session); /** Called when the session failed to be created. */ /** * Called when the session failed to be created. * * @param errorCode The reason for failure. */ void onSessionCreationFailed(@SessionCreationError int errorCode); /** Loading services/companion/java/com/android/server/companion/virtual/computercontrol/ComputerControlSessionProcessor.java +20 −0 Original line number Diff line number Diff line Loading @@ -37,6 +37,12 @@ import com.android.internal.annotations.VisibleForTesting; import com.android.server.LocalServices; import com.android.server.wm.WindowManagerInternal; /** * Handles creation and lifecycle of {@link ComputerControlSession}s. * * <p>This class enforces session creation policies, such as limiting the number of concurrent * sessions and preventing creation when the device is locked. */ public class ComputerControlSessionProcessor { private static final String TAG = ComputerControlSessionProcessor.class.getSimpleName(); Loading @@ -49,6 +55,8 @@ public class ComputerControlSessionProcessor { private final KeyguardManager mKeyguardManager; private final VirtualDeviceFactory mVirtualDeviceFactory; private final WindowManagerInternal mWindowManagerInternal; /** The binders of all currently active sessions. */ private final ArraySet<IBinder> mSessions = new ArraySet<>(); public ComputerControlSessionProcessor( Loading @@ -61,6 +69,10 @@ public class ComputerControlSessionProcessor { /** * Process a new session creation request. * * <p>A new session will be created. In case of failure, the * {@link IComputerControlSessionCallback#onSessionCreationFailed} method on the provided * {@code callback} will be invoked. */ public void processNewSessionRequest( @NonNull AttributionSource attributionSource, Loading Loading @@ -91,6 +103,7 @@ public class ComputerControlSessionProcessor { } } /** Notifies the client that session creation failed. */ private void dispatchSessionCreationFailed(IComputerControlSessionCallback callback, ComputerControlSessionParams params, int reason) { try { Loading @@ -101,6 +114,11 @@ public class ComputerControlSessionProcessor { } } /** * Listener for when a {@link ComputerControlSessionImpl} is closed. * * <p>Removes the session from the set of active sessions and notifies the client. */ private class OnSessionClosedListener implements ComputerControlSessionImpl.OnClosedListener { private final String mSessionName; private final IComputerControlSessionCallback mAppCallback; Loading @@ -115,6 +133,8 @@ public class ComputerControlSessionProcessor { public void onClosed(IBinder token) { synchronized (mSessions) { if (!mSessions.remove(token)) { // The session was already removed, which can happen if close() is called // multiple times. return; } } Loading services/tests/servicestests/src/com/android/server/companion/virtual/computercontrol/ComputerControlSessionProcessorTest.java +2 −0 Original line number Diff line number Diff line Loading @@ -130,7 +130,9 @@ public class ComputerControlSessionProcessorTest { verify(mComputerControlSessionCallback) .onSessionCreationFailed(ComputerControlSession.ERROR_SESSION_LIMIT_REACHED); // Close the first session. mSessionArgumentCaptor.getAllValues().getFirst().close(); // Closing an already-closed session should be a no-op. mSessionArgumentCaptor.getAllValues().getFirst().close(); verify(mComputerControlSessionCallback, times(1)).onSessionClosed(); Loading Loading
core/java/android/companion/virtual/computercontrol/ComputerControlSession.java +5 −1 Original line number Diff line number Diff line Loading @@ -140,7 +140,11 @@ public final class ComputerControlSession implements AutoCloseable { /** Called when the session has been successfully created. */ void onSessionCreated(@NonNull ComputerControlSession session); /** Called when the session failed to be created. */ /** * Called when the session failed to be created. * * @param errorCode The reason for failure. */ void onSessionCreationFailed(@SessionCreationError int errorCode); /** Loading
services/companion/java/com/android/server/companion/virtual/computercontrol/ComputerControlSessionProcessor.java +20 −0 Original line number Diff line number Diff line Loading @@ -37,6 +37,12 @@ import com.android.internal.annotations.VisibleForTesting; import com.android.server.LocalServices; import com.android.server.wm.WindowManagerInternal; /** * Handles creation and lifecycle of {@link ComputerControlSession}s. * * <p>This class enforces session creation policies, such as limiting the number of concurrent * sessions and preventing creation when the device is locked. */ public class ComputerControlSessionProcessor { private static final String TAG = ComputerControlSessionProcessor.class.getSimpleName(); Loading @@ -49,6 +55,8 @@ public class ComputerControlSessionProcessor { private final KeyguardManager mKeyguardManager; private final VirtualDeviceFactory mVirtualDeviceFactory; private final WindowManagerInternal mWindowManagerInternal; /** The binders of all currently active sessions. */ private final ArraySet<IBinder> mSessions = new ArraySet<>(); public ComputerControlSessionProcessor( Loading @@ -61,6 +69,10 @@ public class ComputerControlSessionProcessor { /** * Process a new session creation request. * * <p>A new session will be created. In case of failure, the * {@link IComputerControlSessionCallback#onSessionCreationFailed} method on the provided * {@code callback} will be invoked. */ public void processNewSessionRequest( @NonNull AttributionSource attributionSource, Loading Loading @@ -91,6 +103,7 @@ public class ComputerControlSessionProcessor { } } /** Notifies the client that session creation failed. */ private void dispatchSessionCreationFailed(IComputerControlSessionCallback callback, ComputerControlSessionParams params, int reason) { try { Loading @@ -101,6 +114,11 @@ public class ComputerControlSessionProcessor { } } /** * Listener for when a {@link ComputerControlSessionImpl} is closed. * * <p>Removes the session from the set of active sessions and notifies the client. */ private class OnSessionClosedListener implements ComputerControlSessionImpl.OnClosedListener { private final String mSessionName; private final IComputerControlSessionCallback mAppCallback; Loading @@ -115,6 +133,8 @@ public class ComputerControlSessionProcessor { public void onClosed(IBinder token) { synchronized (mSessions) { if (!mSessions.remove(token)) { // The session was already removed, which can happen if close() is called // multiple times. return; } } Loading
services/tests/servicestests/src/com/android/server/companion/virtual/computercontrol/ComputerControlSessionProcessorTest.java +2 −0 Original line number Diff line number Diff line Loading @@ -130,7 +130,9 @@ public class ComputerControlSessionProcessorTest { verify(mComputerControlSessionCallback) .onSessionCreationFailed(ComputerControlSession.ERROR_SESSION_LIMIT_REACHED); // Close the first session. mSessionArgumentCaptor.getAllValues().getFirst().close(); // Closing an already-closed session should be a no-op. mSessionArgumentCaptor.getAllValues().getFirst().close(); verify(mComputerControlSessionCallback, times(1)).onSessionClosed(); Loading