diff --git a/Assets/Tests/InputSystem/CoreTests_Devices.cs b/Assets/Tests/InputSystem/CoreTests_Devices.cs index 662f9b751d..96c5f2b366 100644 --- a/Assets/Tests/InputSystem/CoreTests_Devices.cs +++ b/Assets/Tests/InputSystem/CoreTests_Devices.cs @@ -1501,6 +1501,52 @@ public void Devices_WhenRetainedOnDisconnectedList_CanBeReconnected(string devic Assert.That(InputSystem.disconnectedDevices, Is.Empty); } + // https://fogbugz.unity3d.com/f/cases/1404320 + [Test] + [Category("Devices")] + public void Devices_CanReconnectDevice_WhenDisconnectedWhileAppIsOutOfFocus() + { + runtime.runInBackground = true; + + var deviceDesc = new InputDeviceDescription + { + deviceClass = "Gamepad", + product = "TestDevice", + serial = "1234" + }; + + var deviceId = runtime.ReportNewInputDevice(deviceDesc); + InputSystem.Update(); + + var device = InputSystem.GetDeviceById(deviceId); + Assert.That(device, Is.Not.Null); + + // Loose focus. + runtime.PlayerFocusLost(); + InputSystem.Update(); + + // Disconnect. + var inputEvent = DeviceRemoveEvent.Create(deviceId, runtime.currentTime); + InputSystem.QueueEvent(ref inputEvent); + InputSystem.Update(); + + Assert.That(InputSystem.disconnectedDevices, Is.EquivalentTo(new[] { device })); + Assert.That(InputSystem.devices, Is.Empty); + + // Regain focus. + runtime.PlayerFocusGained(); + InputSystem.Update(); + + var newDeviceId = runtime.ReportNewInputDevice(deviceDesc); + InputSystem.Update(); + + var newDevice = InputSystem.GetDeviceById(newDeviceId); + Assert.That(newDevice, Is.SameAs(device)); + + Assert.That(device.added, Is.True); + Assert.That(device.enabled, Is.True); + } + [Test] [Category("Devices")] public void Devices_WhenRemoved_DoNotEmergeOnUnsupportedList() diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index d782af5e9a..920f78a834 100755 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -59,6 +59,7 @@ however, it has to be formatted properly to pass verification tests. - Fixed missing tooltips in PlayerInputManagerEditor for the Player Limit and Fixed Splitscreen sizes labels ([case 1396945](https://issuetracker.unity3d.com/issues/player-input-manager-pops-up-placeholder-text-when-hovering-over-it)). - Fixed DualShock 4 controllers not working in some scenarios by adding support for extended mode HID reports ([case 1281633](https://issuetracker.unity3d.com/issues/input-system-dualshock4-controller-returns-random-input-values-when-connected-via-bluetooth-while-steam-is-running), case 1409867). - Fixed `BackgroundBehavior.IgnoreFocus` having no effect when `Application.runInBackground` was false ([case 1400456](https://issuetracker.unity3d.com/issues/xr-head-tracking-lost-when-lost-focus-with-action-based-trackedposedriver-on-android)). +- Fixed an issue where a device was left disabled when it was disconnected while an application was out-of-focus and then re-connected when in-focus (case 1404320). #### Actions diff --git a/Packages/com.unity.inputsystem/InputSystem/InputManager.cs b/Packages/com.unity.inputsystem/InputSystem/InputManager.cs index 777625a6c5..d3f06ce21e 100644 --- a/Packages/com.unity.inputsystem/InputSystem/InputManager.cs +++ b/Packages/com.unity.inputsystem/InputSystem/InputManager.cs @@ -2248,6 +2248,7 @@ private void OnNativeDeviceDiscovered(int deviceId, string deviceDescriptor) device.m_DeviceId = deviceId; device.m_DeviceFlags |= InputDevice.DeviceFlags.Native; device.m_DeviceFlags &= ~InputDevice.DeviceFlags.DisabledInFrontend; + device.m_DeviceFlags &= ~InputDevice.DeviceFlags.DisabledWhileInBackground; device.m_DeviceFlags &= ~InputDevice.DeviceFlags.DisabledStateHasBeenQueriedFromRuntime; AddDevice(device);