Loading core/java/android/os/vibrator/flags.aconfig +0 −10 Original line number Diff line number Diff line Loading @@ -136,16 +136,6 @@ flag { } } flag { namespace: "haptics" name: "fix_vibration_thread_callback_handling" description: "Fix how the VibrationThread handles late callbacks from the vibrator HAL" bug: "395005081" metadata { purpose: PURPOSE_BUGFIX } } flag { namespace: "haptics" name: "fix_external_vibration_system_update_aware" Loading services/core/java/com/android/server/vibrator/SetAmplitudeVibratorStep.java +0 −28 Original line number Diff line number Diff line Loading @@ -20,7 +20,6 @@ import android.annotation.NonNull; import android.os.SystemClock; import android.os.Trace; import android.os.VibrationEffect; import android.os.vibrator.Flags; import android.os.vibrator.StepSegment; import android.os.vibrator.VibrationEffectSegment; import android.util.Slog; Loading Loading @@ -48,33 +47,6 @@ final class SetAmplitudeVibratorStep extends AbstractComposedVibratorStep { super(conductor, startTime, controller, effect, index, pendingVibratorOffDeadline); } @Override public boolean acceptVibratorCompleteCallback(int vibratorId) { if (Flags.fixVibrationThreadCallbackHandling()) { // TODO: remove this method once flag removed. return super.acceptVibratorCompleteCallback(vibratorId); } // Ensure the super method is called and will reset the off timeout and boolean flag. // This is true if the vibrator was ON and this callback has the same vibratorId. if (!super.acceptVibratorCompleteCallback(vibratorId)) { return false; } // Timings are tightly controlled here, so only trigger this step if the vibrator was // supposed to be ON but has completed prematurely, to turn it back on as soon as // possible. If the vibrator turned off during a zero-amplitude step, just wait for // the correct start time of this step before playing it. boolean shouldAcceptCallback = (SystemClock.uptimeMillis() < startTime) && (controller.getCurrentAmplitude() > 0); if (VibrationThread.DEBUG) { Slog.d(VibrationThread.TAG, "Amplitude step received completion callback from " + vibratorId + ", accepted = " + shouldAcceptCallback); } return shouldAcceptCallback; } @NonNull @Override public List<Step> play() { Loading services/core/java/com/android/server/vibrator/VibrationStepConductor.java +1 −5 Original line number Diff line number Diff line Loading @@ -433,8 +433,7 @@ final class VibrationStepConductor { } synchronized (mLock) { if (Flags.fixVibrationThreadCallbackHandling() && mSignalVibratorStepIds.get(vibratorId) != stepId) { if (mSignalVibratorStepIds.get(vibratorId) != stepId) { if (DEBUG) { Slog.d(TAG, "Vibrator " + vibratorId + " callback for step=" + stepId + " ignored, current step=" + mSignalVibratorStepIds.get(vibratorId)); Loading Loading @@ -665,9 +664,6 @@ final class VibrationStepConductor { * triggered too late by the HAL, preventing them from affecting the ongoing vibration playback. */ public int nextVibratorCallbackStepId(int vibratorId) { if (!Flags.fixVibrationThreadCallbackHandling()) { return 0; } if (Build.IS_DEBUGGABLE) { expectIsVibrationThread(true); } Loading services/core/jni/com_android_server_vibrator_VibratorController.cpp +1 −16 Original line number Diff line number Diff line Loading @@ -117,31 +117,17 @@ public: } std::function<void()> createCallback(jlong vibrationId, jlong stepId) { auto callbackId = ++mCallbackId; return [vibrationId, stepId, callbackId, this]() { auto currentCallbackId = mCallbackId.load(); if (!android_os_vibrator_fix_vibration_thread_callback_handling() && currentCallbackId != callbackId) { // This callback is from an older HAL call that is no longer relevant return; } return [vibrationId, stepId, this]() { auto jniEnv = GetOrAttachJNIEnvironment(sJvm); jniEnv->CallVoidMethod(mCallbackListener, sMethodIdOnComplete, mVibratorId, vibrationId, stepId); }; } void disableOldCallbacks() { // TODO remove this once android_os_vibrator_fix_vibration_thread_callback_handling removed mCallbackId++; } private: const std::shared_ptr<vibrator::HalController> mHal; const int32_t mVibratorId; const jobject mCallbackListener; // TODO remove this once android_os_vibrator_fix_vibration_thread_callback_handling removed std::atomic<int64_t> mCallbackId; }; static Aidl::BrakingPwle brakingPwle(Aidl::Braking braking, int32_t duration) { Loading Loading @@ -271,7 +257,6 @@ static void vibratorOff(JNIEnv* env, jclass /* clazz */, jlong ptr) { } auto offFn = [](vibrator::HalWrapper* hal) { return hal->off(); }; wrapper->halCall<void>(offFn, "off"); wrapper->disableOldCallbacks(); } static void vibratorSetAmplitude(JNIEnv* env, jclass /* clazz */, jlong ptr, jfloat amplitude) { Loading services/tests/vibrator/src/com/android/server/vibrator/VibrationThreadTest.java +2 −22 Original line number Diff line number Diff line Loading @@ -247,7 +247,6 @@ public class VibrationThreadTest { assertThat(mVibratorProviders.get(VIBRATOR_ID).getAmplitudes()).isEmpty(); } @EnableFlags(Flags.FLAG_FIX_VIBRATION_THREAD_CALLBACK_HANDLING) @Test public void vibrate_singleVibratorWaveform_runsVibrationAndChangesAmplitudes() { mVibratorProviders.get(VIBRATOR_ID).setCapabilities(IVibrator.CAP_AMPLITUDE_CONTROL); Loading @@ -270,10 +269,7 @@ public class VibrationThreadTest { } @Test @EnableFlags({ Flags.FLAG_ADAPTIVE_HAPTICS_ENABLED, Flags.FLAG_FIX_VIBRATION_THREAD_CALLBACK_HANDLING, }) @EnableFlags(Flags.FLAG_ADAPTIVE_HAPTICS_ENABLED) public void vibrate_singleWaveformWithAdaptiveHapticsScaling_scalesAmplitudesProperly() { // No user settings scale. setUserSetting(Settings.System.RING_VIBRATION_INTENSITY, Loading @@ -300,10 +296,7 @@ public class VibrationThreadTest { } @Test @EnableFlags({ Flags.FLAG_ADAPTIVE_HAPTICS_ENABLED, Flags.FLAG_FIX_VIBRATION_THREAD_CALLBACK_HANDLING, }) @EnableFlags(Flags.FLAG_ADAPTIVE_HAPTICS_ENABLED) public void vibrate_withVibrationParamsRequestStalling_timeoutRequestAndApplyNoScaling() { // No user settings scale. setUserSetting(Settings.System.RING_VIBRATION_INTENSITY, Loading Loading @@ -364,7 +357,6 @@ public class VibrationThreadTest { } } @EnableFlags(Flags.FLAG_FIX_VIBRATION_THREAD_CALLBACK_HANDLING) @Test public void vibrate_singleVibratorRepeatingShortAlwaysOnWaveform_turnsVibratorOnForLonger() throws Exception { Loading @@ -388,7 +380,6 @@ public class VibrationThreadTest { .containsExactly(expectedOneShot(5000)).inOrder(); } @EnableFlags(Flags.FLAG_FIX_VIBRATION_THREAD_CALLBACK_HANDLING) @Test public void vibrate_singleVibratorPatternWithZeroDurationSteps_skipsZeroDurationSteps() { mVibratorProviders.get(VIBRATOR_ID).setCapabilities(IVibrator.CAP_AMPLITUDE_CONTROL); Loading @@ -408,7 +399,6 @@ public class VibrationThreadTest { .containsExactlyElementsIn(expectedOneShots(100L, 150L)).inOrder(); } @EnableFlags(Flags.FLAG_FIX_VIBRATION_THREAD_CALLBACK_HANDLING) @Test public void vibrate_singleVibratorPatternWithZeroDurationAndAmplitude_skipsZeroDurationSteps() { mVibratorProviders.get(VIBRATOR_ID).setCapabilities(IVibrator.CAP_AMPLITUDE_CONTROL); Loading @@ -430,7 +420,6 @@ public class VibrationThreadTest { .containsExactlyElementsIn(expectedOneShots(200L, 50L)).inOrder(); } @EnableFlags(Flags.FLAG_FIX_VIBRATION_THREAD_CALLBACK_HANDLING) @LargeTest @Test public void vibrate_singleVibratorRepeatingPatternWithZeroDurationSteps_repeatsEffectCorrectly() Loading Loading @@ -463,7 +452,6 @@ public class VibrationThreadTest { .inOrder(); } @EnableFlags(Flags.FLAG_FIX_VIBRATION_THREAD_CALLBACK_HANDLING) @Test public void vibrate_singleVibratorPatternWithCallbackDelay_oldCallbacksIgnored() { FakeVibratorControllerProvider fakeVibrator = mVibratorProviders.get(VIBRATOR_ID); Loading Loading @@ -547,7 +535,6 @@ public class VibrationThreadTest { assertThat(fakeVibrator.getEffectSegments(vibration.id)).hasSize(10); } @EnableFlags(Flags.FLAG_FIX_VIBRATION_THREAD_CALLBACK_HANDLING) @Test public void vibrate_singleVibratorRepeatingLongAlwaysOnWaveform_turnsVibratorOnForACycle() throws Exception { Loading Loading @@ -711,7 +698,6 @@ public class VibrationThreadTest { .containsExactly(expectedPrebaked(VibrationEffect.EFFECT_THUD)).inOrder(); } @EnableFlags(Flags.FLAG_FIX_VIBRATION_THREAD_CALLBACK_HANDLING) @Test public void vibrate_singleVibratorPrebakedAndUnsupportedEffectWithFallback_runsFallback() { mVibratorProviders.get(VIBRATOR_ID).setCapabilities(IVibrator.CAP_AMPLITUDE_CONTROL); Loading Loading @@ -1259,7 +1245,6 @@ public class VibrationThreadTest { .containsExactly(expected).inOrder(); } @EnableFlags(Flags.FLAG_FIX_VIBRATION_THREAD_CALLBACK_HANDLING) @Test public void vibrate_multipleStereo_runsVibrationOnRightVibrators() { mockVibrators(1, 2, 3, 4); Loading Loading @@ -1492,7 +1477,6 @@ public class VibrationThreadTest { assertThat(mVibratorProviders.get(1).getAmplitudes()).isEmpty(); } @EnableFlags(Flags.FLAG_FIX_VIBRATION_THREAD_CALLBACK_HANDLING) @Test public void vibrate_multipleWaveforms_playsWaveformsInParallel() throws Exception { mockVibrators(1, 2, 3); Loading Loading @@ -1811,7 +1795,6 @@ public class VibrationThreadTest { assertThat(mControllers.get(VIBRATOR_ID).isVibrating()).isFalse(); } @EnableFlags(Flags.FLAG_FIX_VIBRATION_THREAD_CALLBACK_HANDLING) @Test public void vibrate_waveformWithRampDown_addsRampDownAfterVibrationCompleted() { when(mVibrationConfigMock.getRampDownDurationMs()).thenReturn(15); Loading Loading @@ -1839,7 +1822,6 @@ public class VibrationThreadTest { } } @EnableFlags(Flags.FLAG_FIX_VIBRATION_THREAD_CALLBACK_HANDLING) @Test public void vibrate_waveformWithRampDown_triggersCallbackWhenOriginalVibrationEnds() throws Exception { Loading Loading @@ -1870,7 +1852,6 @@ public class VibrationThreadTest { verify(mManagerHooks).onVibrationThreadReleased(vibration.id); } @EnableFlags(Flags.FLAG_FIX_VIBRATION_THREAD_CALLBACK_HANDLING) @Test public void vibrate_waveformCancelledWithRampDown_addsRampDownAfterVibrationCancelled() throws Exception { Loading Loading @@ -2065,7 +2046,6 @@ public class VibrationThreadTest { .containsExactly(expectedPrebaked(EFFECT_CLICK)).inOrder(); } @EnableFlags(Flags.FLAG_FIX_VIBRATION_THREAD_CALLBACK_HANDLING) @Test public void vibrate_multipleVibratorsSequentialInSession_runsInOrderWithoutDelaysAndNoOffs() { mockVibrators(1, 2, 3); Loading Loading
core/java/android/os/vibrator/flags.aconfig +0 −10 Original line number Diff line number Diff line Loading @@ -136,16 +136,6 @@ flag { } } flag { namespace: "haptics" name: "fix_vibration_thread_callback_handling" description: "Fix how the VibrationThread handles late callbacks from the vibrator HAL" bug: "395005081" metadata { purpose: PURPOSE_BUGFIX } } flag { namespace: "haptics" name: "fix_external_vibration_system_update_aware" Loading
services/core/java/com/android/server/vibrator/SetAmplitudeVibratorStep.java +0 −28 Original line number Diff line number Diff line Loading @@ -20,7 +20,6 @@ import android.annotation.NonNull; import android.os.SystemClock; import android.os.Trace; import android.os.VibrationEffect; import android.os.vibrator.Flags; import android.os.vibrator.StepSegment; import android.os.vibrator.VibrationEffectSegment; import android.util.Slog; Loading Loading @@ -48,33 +47,6 @@ final class SetAmplitudeVibratorStep extends AbstractComposedVibratorStep { super(conductor, startTime, controller, effect, index, pendingVibratorOffDeadline); } @Override public boolean acceptVibratorCompleteCallback(int vibratorId) { if (Flags.fixVibrationThreadCallbackHandling()) { // TODO: remove this method once flag removed. return super.acceptVibratorCompleteCallback(vibratorId); } // Ensure the super method is called and will reset the off timeout and boolean flag. // This is true if the vibrator was ON and this callback has the same vibratorId. if (!super.acceptVibratorCompleteCallback(vibratorId)) { return false; } // Timings are tightly controlled here, so only trigger this step if the vibrator was // supposed to be ON but has completed prematurely, to turn it back on as soon as // possible. If the vibrator turned off during a zero-amplitude step, just wait for // the correct start time of this step before playing it. boolean shouldAcceptCallback = (SystemClock.uptimeMillis() < startTime) && (controller.getCurrentAmplitude() > 0); if (VibrationThread.DEBUG) { Slog.d(VibrationThread.TAG, "Amplitude step received completion callback from " + vibratorId + ", accepted = " + shouldAcceptCallback); } return shouldAcceptCallback; } @NonNull @Override public List<Step> play() { Loading
services/core/java/com/android/server/vibrator/VibrationStepConductor.java +1 −5 Original line number Diff line number Diff line Loading @@ -433,8 +433,7 @@ final class VibrationStepConductor { } synchronized (mLock) { if (Flags.fixVibrationThreadCallbackHandling() && mSignalVibratorStepIds.get(vibratorId) != stepId) { if (mSignalVibratorStepIds.get(vibratorId) != stepId) { if (DEBUG) { Slog.d(TAG, "Vibrator " + vibratorId + " callback for step=" + stepId + " ignored, current step=" + mSignalVibratorStepIds.get(vibratorId)); Loading Loading @@ -665,9 +664,6 @@ final class VibrationStepConductor { * triggered too late by the HAL, preventing them from affecting the ongoing vibration playback. */ public int nextVibratorCallbackStepId(int vibratorId) { if (!Flags.fixVibrationThreadCallbackHandling()) { return 0; } if (Build.IS_DEBUGGABLE) { expectIsVibrationThread(true); } Loading
services/core/jni/com_android_server_vibrator_VibratorController.cpp +1 −16 Original line number Diff line number Diff line Loading @@ -117,31 +117,17 @@ public: } std::function<void()> createCallback(jlong vibrationId, jlong stepId) { auto callbackId = ++mCallbackId; return [vibrationId, stepId, callbackId, this]() { auto currentCallbackId = mCallbackId.load(); if (!android_os_vibrator_fix_vibration_thread_callback_handling() && currentCallbackId != callbackId) { // This callback is from an older HAL call that is no longer relevant return; } return [vibrationId, stepId, this]() { auto jniEnv = GetOrAttachJNIEnvironment(sJvm); jniEnv->CallVoidMethod(mCallbackListener, sMethodIdOnComplete, mVibratorId, vibrationId, stepId); }; } void disableOldCallbacks() { // TODO remove this once android_os_vibrator_fix_vibration_thread_callback_handling removed mCallbackId++; } private: const std::shared_ptr<vibrator::HalController> mHal; const int32_t mVibratorId; const jobject mCallbackListener; // TODO remove this once android_os_vibrator_fix_vibration_thread_callback_handling removed std::atomic<int64_t> mCallbackId; }; static Aidl::BrakingPwle brakingPwle(Aidl::Braking braking, int32_t duration) { Loading Loading @@ -271,7 +257,6 @@ static void vibratorOff(JNIEnv* env, jclass /* clazz */, jlong ptr) { } auto offFn = [](vibrator::HalWrapper* hal) { return hal->off(); }; wrapper->halCall<void>(offFn, "off"); wrapper->disableOldCallbacks(); } static void vibratorSetAmplitude(JNIEnv* env, jclass /* clazz */, jlong ptr, jfloat amplitude) { Loading
services/tests/vibrator/src/com/android/server/vibrator/VibrationThreadTest.java +2 −22 Original line number Diff line number Diff line Loading @@ -247,7 +247,6 @@ public class VibrationThreadTest { assertThat(mVibratorProviders.get(VIBRATOR_ID).getAmplitudes()).isEmpty(); } @EnableFlags(Flags.FLAG_FIX_VIBRATION_THREAD_CALLBACK_HANDLING) @Test public void vibrate_singleVibratorWaveform_runsVibrationAndChangesAmplitudes() { mVibratorProviders.get(VIBRATOR_ID).setCapabilities(IVibrator.CAP_AMPLITUDE_CONTROL); Loading @@ -270,10 +269,7 @@ public class VibrationThreadTest { } @Test @EnableFlags({ Flags.FLAG_ADAPTIVE_HAPTICS_ENABLED, Flags.FLAG_FIX_VIBRATION_THREAD_CALLBACK_HANDLING, }) @EnableFlags(Flags.FLAG_ADAPTIVE_HAPTICS_ENABLED) public void vibrate_singleWaveformWithAdaptiveHapticsScaling_scalesAmplitudesProperly() { // No user settings scale. setUserSetting(Settings.System.RING_VIBRATION_INTENSITY, Loading @@ -300,10 +296,7 @@ public class VibrationThreadTest { } @Test @EnableFlags({ Flags.FLAG_ADAPTIVE_HAPTICS_ENABLED, Flags.FLAG_FIX_VIBRATION_THREAD_CALLBACK_HANDLING, }) @EnableFlags(Flags.FLAG_ADAPTIVE_HAPTICS_ENABLED) public void vibrate_withVibrationParamsRequestStalling_timeoutRequestAndApplyNoScaling() { // No user settings scale. setUserSetting(Settings.System.RING_VIBRATION_INTENSITY, Loading Loading @@ -364,7 +357,6 @@ public class VibrationThreadTest { } } @EnableFlags(Flags.FLAG_FIX_VIBRATION_THREAD_CALLBACK_HANDLING) @Test public void vibrate_singleVibratorRepeatingShortAlwaysOnWaveform_turnsVibratorOnForLonger() throws Exception { Loading @@ -388,7 +380,6 @@ public class VibrationThreadTest { .containsExactly(expectedOneShot(5000)).inOrder(); } @EnableFlags(Flags.FLAG_FIX_VIBRATION_THREAD_CALLBACK_HANDLING) @Test public void vibrate_singleVibratorPatternWithZeroDurationSteps_skipsZeroDurationSteps() { mVibratorProviders.get(VIBRATOR_ID).setCapabilities(IVibrator.CAP_AMPLITUDE_CONTROL); Loading @@ -408,7 +399,6 @@ public class VibrationThreadTest { .containsExactlyElementsIn(expectedOneShots(100L, 150L)).inOrder(); } @EnableFlags(Flags.FLAG_FIX_VIBRATION_THREAD_CALLBACK_HANDLING) @Test public void vibrate_singleVibratorPatternWithZeroDurationAndAmplitude_skipsZeroDurationSteps() { mVibratorProviders.get(VIBRATOR_ID).setCapabilities(IVibrator.CAP_AMPLITUDE_CONTROL); Loading @@ -430,7 +420,6 @@ public class VibrationThreadTest { .containsExactlyElementsIn(expectedOneShots(200L, 50L)).inOrder(); } @EnableFlags(Flags.FLAG_FIX_VIBRATION_THREAD_CALLBACK_HANDLING) @LargeTest @Test public void vibrate_singleVibratorRepeatingPatternWithZeroDurationSteps_repeatsEffectCorrectly() Loading Loading @@ -463,7 +452,6 @@ public class VibrationThreadTest { .inOrder(); } @EnableFlags(Flags.FLAG_FIX_VIBRATION_THREAD_CALLBACK_HANDLING) @Test public void vibrate_singleVibratorPatternWithCallbackDelay_oldCallbacksIgnored() { FakeVibratorControllerProvider fakeVibrator = mVibratorProviders.get(VIBRATOR_ID); Loading Loading @@ -547,7 +535,6 @@ public class VibrationThreadTest { assertThat(fakeVibrator.getEffectSegments(vibration.id)).hasSize(10); } @EnableFlags(Flags.FLAG_FIX_VIBRATION_THREAD_CALLBACK_HANDLING) @Test public void vibrate_singleVibratorRepeatingLongAlwaysOnWaveform_turnsVibratorOnForACycle() throws Exception { Loading Loading @@ -711,7 +698,6 @@ public class VibrationThreadTest { .containsExactly(expectedPrebaked(VibrationEffect.EFFECT_THUD)).inOrder(); } @EnableFlags(Flags.FLAG_FIX_VIBRATION_THREAD_CALLBACK_HANDLING) @Test public void vibrate_singleVibratorPrebakedAndUnsupportedEffectWithFallback_runsFallback() { mVibratorProviders.get(VIBRATOR_ID).setCapabilities(IVibrator.CAP_AMPLITUDE_CONTROL); Loading Loading @@ -1259,7 +1245,6 @@ public class VibrationThreadTest { .containsExactly(expected).inOrder(); } @EnableFlags(Flags.FLAG_FIX_VIBRATION_THREAD_CALLBACK_HANDLING) @Test public void vibrate_multipleStereo_runsVibrationOnRightVibrators() { mockVibrators(1, 2, 3, 4); Loading Loading @@ -1492,7 +1477,6 @@ public class VibrationThreadTest { assertThat(mVibratorProviders.get(1).getAmplitudes()).isEmpty(); } @EnableFlags(Flags.FLAG_FIX_VIBRATION_THREAD_CALLBACK_HANDLING) @Test public void vibrate_multipleWaveforms_playsWaveformsInParallel() throws Exception { mockVibrators(1, 2, 3); Loading Loading @@ -1811,7 +1795,6 @@ public class VibrationThreadTest { assertThat(mControllers.get(VIBRATOR_ID).isVibrating()).isFalse(); } @EnableFlags(Flags.FLAG_FIX_VIBRATION_THREAD_CALLBACK_HANDLING) @Test public void vibrate_waveformWithRampDown_addsRampDownAfterVibrationCompleted() { when(mVibrationConfigMock.getRampDownDurationMs()).thenReturn(15); Loading Loading @@ -1839,7 +1822,6 @@ public class VibrationThreadTest { } } @EnableFlags(Flags.FLAG_FIX_VIBRATION_THREAD_CALLBACK_HANDLING) @Test public void vibrate_waveformWithRampDown_triggersCallbackWhenOriginalVibrationEnds() throws Exception { Loading Loading @@ -1870,7 +1852,6 @@ public class VibrationThreadTest { verify(mManagerHooks).onVibrationThreadReleased(vibration.id); } @EnableFlags(Flags.FLAG_FIX_VIBRATION_THREAD_CALLBACK_HANDLING) @Test public void vibrate_waveformCancelledWithRampDown_addsRampDownAfterVibrationCancelled() throws Exception { Loading Loading @@ -2065,7 +2046,6 @@ public class VibrationThreadTest { .containsExactly(expectedPrebaked(EFFECT_CLICK)).inOrder(); } @EnableFlags(Flags.FLAG_FIX_VIBRATION_THREAD_CALLBACK_HANDLING) @Test public void vibrate_multipleVibratorsSequentialInSession_runsInOrderWithoutDelaysAndNoOffs() { mockVibrators(1, 2, 3); Loading