Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions Assets/Tests/InputSystem/CoreTests_Devices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions Packages/com.unity.inputsystem/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions Packages/com.unity.inputsystem/InputSystem/InputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down