mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2026-10-21 07:46:57 +00:00
Avoid unnecessary reinitialization of PS4/PS5 gamepads during stream exit
onInputDeviceChanged() is triggered by starting/stopping pointer capture, so we should unregister our callbacks before that happens to avoid triggering several gamepad context reinitializations right as the stream is exiting
This commit is contained in:
1 parent
fc77322f59
commit
c356862ac1
3 files changed
+34
-3
No files matched your search
@@ -114,6 +114,7 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD
|
||||
private final double stickDeadzone;
|
||||
private final InputDeviceContext defaultContext = new InputDeviceContext();
|
||||
private final GameGestures gestures;
|
||||
private final InputManager inputManager;
|
||||
private final Vibrator deviceVibrator;
|
||||
private final VibratorManager deviceVibratorManager;
|
||||
private final SensorManager deviceSensorManager;
|
||||
@@ -134,6 +135,7 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD
|
||||
this.prefConfig = prefConfig;
|
||||
this.deviceVibrator = (Vibrator) activityContext.getSystemService(Context.VIBRATOR_SERVICE);
|
||||
this.deviceSensorManager = (SensorManager) activityContext.getSystemService(Context.SENSOR_SERVICE);
|
||||
this.inputManager = (InputManager) activityContext.getSystemService(Context.INPUT_SERVICE);
|
||||
this.mainThreadHandler = new Handler(Looper.getMainLooper());
|
||||
|
||||
// Create a HandlerThread to process battery state updates. These can be slow enough
|
||||
@@ -205,6 +207,9 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD
|
||||
// currentControllers set which will allow them to properly unplug
|
||||
// if they are removed.
|
||||
initialControllers = getAttachedControllerMask(activityContext);
|
||||
|
||||
// Register ourselves for input device notifications
|
||||
inputManager.registerInputDeviceListener(this, null);
|
||||
}
|
||||
|
||||
private static InputDevice.MotionRange getMotionRangeForJoystickAxis(InputDevice dev, int axis) {
|
||||
@@ -260,9 +265,16 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
if (stopped) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Stop new device contexts from being created or used
|
||||
stopped = true;
|
||||
|
||||
// Unregister our input device callbacks
|
||||
inputManager.unregisterInputDeviceListener(this);
|
||||
|
||||
for (int i = 0; i < inputDeviceContexts.size(); i++) {
|
||||
InputDeviceContext deviceContext = inputDeviceContexts.valueAt(i);
|
||||
deviceContext.destroy();
|
||||
|
||||
Reference in new issue
Block a user