Merge "Use dedicated lock in InputController" into udc-dev

This commit is contained in:
Ján Sebechlebský
2023-03-01 10:37:40 +00:00
committed by Android (Google) Code Review
4 changed files with 6 additions and 8 deletions

View File

@@ -88,7 +88,7 @@ class InputController {
*/
private static final int DEVICE_NAME_MAX_LENGTH = 80;
final Object mLock;
final Object mLock = new Object();
/* Token -> file descriptor associations. */
@GuardedBy("mLock")
@@ -101,18 +101,17 @@ class InputController {
private final WindowManager mWindowManager;
private final DeviceCreationThreadVerifier mThreadVerifier;
InputController(@NonNull Object lock, @NonNull Handler handler,
InputController(@NonNull Handler handler,
@NonNull WindowManager windowManager) {
this(lock, new NativeWrapper(), handler, windowManager,
this(new NativeWrapper(), handler, windowManager,
// Verify that virtual devices are not created on the handler thread.
() -> !handler.getLooper().isCurrentThread());
}
@VisibleForTesting
InputController(@NonNull Object lock, @NonNull NativeWrapper nativeWrapper,
InputController(@NonNull NativeWrapper nativeWrapper,
@NonNull Handler handler, @NonNull WindowManager windowManager,
@NonNull DeviceCreationThreadVerifier threadVerifier) {
mLock = lock;
mHandler = handler;
mNativeWrapper = nativeWrapper;
mDisplayManagerInternal = LocalServices.getService(DisplayManagerInternal.class);

View File

@@ -259,7 +259,6 @@ final class VirtualDeviceImpl extends IVirtualDevice.Stub
mDisplayManager = displayManager;
if (inputController == null) {
mInputController = new InputController(
mVirtualDeviceLock,
context.getMainThreadHandler(),
context.getSystemService(WindowManager.class));
} else {

View File

@@ -87,7 +87,7 @@ public class InputControllerTest {
// Allow virtual devices to be created on the looper thread for testing.
final InputController.DeviceCreationThreadVerifier threadVerifier = () -> true;
mInputController = new InputController(new Object(), mNativeWrapperMock,
mInputController = new InputController(mNativeWrapperMock,
new Handler(TestableLooper.get(this).getLooper()),
InstrumentationRegistry.getTargetContext().getSystemService(WindowManager.class),
threadVerifier);

View File

@@ -355,7 +355,7 @@ public class VirtualDeviceManagerServiceTest {
TestableLooper.get(this), mNativeWrapperMock, mIInputManagerMock);
// Allow virtual devices to be created on the looper thread for testing.
final InputController.DeviceCreationThreadVerifier threadVerifier = () -> true;
mInputController = new InputController(new Object(), mNativeWrapperMock,
mInputController = new InputController(mNativeWrapperMock,
new Handler(TestableLooper.get(this).getLooper()),
mContext.getSystemService(WindowManager.class), threadVerifier);
mSensorController =