Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 884acc65 authored by Lais Andrade's avatar Lais Andrade
Browse files

Remove android.os.vibrator.fix_vibration_thread_callback_handling

Flag cleanup after bug fix fully released.

Fix: 417497422
Test: VibrationThreadTest
Flag: EXEMPT flag removal
Change-Id: I927dd534d88a222eb0aeaabb4d1467a1141be9ce
parent e5094e86
Loading
Loading
Loading
Loading
+0 −10
Original line number Diff line number Diff line
@@ -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"
+0 −28
Original line number Diff line number Diff line
@@ -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;
@@ -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() {
+1 −5
Original line number Diff line number Diff line
@@ -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));
@@ -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);
        }
+1 −16
Original line number Diff line number Diff line
@@ -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) {
@@ -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) {
+2 −22
Original line number Diff line number Diff line
@@ -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);
@@ -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,
@@ -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,
@@ -364,7 +357,6 @@ public class VibrationThreadTest {
        }
    }

    @EnableFlags(Flags.FLAG_FIX_VIBRATION_THREAD_CALLBACK_HANDLING)
    @Test
    public void vibrate_singleVibratorRepeatingShortAlwaysOnWaveform_turnsVibratorOnForLonger()
            throws Exception {
@@ -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);
@@ -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);
@@ -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()
@@ -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);
@@ -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 {
@@ -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);
@@ -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);
@@ -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);
@@ -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);
@@ -1839,7 +1822,6 @@ public class VibrationThreadTest {
        }
    }

    @EnableFlags(Flags.FLAG_FIX_VIBRATION_THREAD_CALLBACK_HANDLING)
    @Test
    public void vibrate_waveformWithRampDown_triggersCallbackWhenOriginalVibrationEnds()
            throws Exception {
@@ -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 {
@@ -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);