Android: Make vibration length variable

Previously we would vibrate for 100 ms on every vibration, which was
especially annoying if a game was doing a bunch of vibrations that were
supposed to be much shorter than that. Now we tell Android to vibrate
for 10 s, then cancel the vibration as soon as the game turns the
vibration off.
This commit is contained in:
JosJuice
2026-07-09 21:05:10 +02:00
parent aaeb6e5dc1
commit b67188cc44
2 changed files with 17 additions and 3 deletions
@@ -69,6 +69,7 @@ jmethodID s_controller_interface_unregister_input_device_listener;
jmethodID s_controller_interface_get_vibrator_manager;
jmethodID s_controller_interface_get_system_vibrator_manager;
jmethodID s_controller_interface_vibrate;
jmethodID s_controller_interface_cancel_vibration;
jclass s_sensor_event_listener_class;
jmethodID s_sensor_event_listener_constructor;
@@ -602,6 +603,11 @@ public:
IDCache::GetEnvForThread()->CallStaticVoidMethod(s_controller_interface_class,
s_controller_interface_vibrate, m_vibrator);
}
else if (old_state >= 0.5 && state < 0.5)
{
IDCache::GetEnvForThread()->CallStaticVoidMethod(
s_controller_interface_class, s_controller_interface_cancel_vibration, m_vibrator);
}
}
private:
@@ -892,6 +898,8 @@ InputBackend::InputBackend(ControllerInterface* controller_interface)
"()Lorg/dolphinemu/dolphinemu/features/input/model/DolphinVibratorManager;");
s_controller_interface_vibrate =
env->GetStaticMethodID(s_controller_interface_class, "vibrate", "(Landroid/os/Vibrator;)V");
s_controller_interface_cancel_vibration = env->GetStaticMethodID(
s_controller_interface_class, "cancelVibration", "(Landroid/os/Vibrator;)V");
env->DeleteLocalRef(controller_interface_class);
const jclass sensor_event_listener_class =