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

Commit edcc63b1 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Remove android.os.vibrator.vibration_thread_handling_hal_failure" into main

parents c709ea04 8324c5df
Loading
Loading
Loading
Loading
+0 −10
Original line number Diff line number Diff line
@@ -110,16 +110,6 @@ flag {
    }
}

flag {
    namespace: "haptics"
    name: "vibration_thread_handling_hal_failure"
    description: "Fixes how VibrationThread handled HAL failures"
    bug: "419572960"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}

flag {
    namespace: "haptics"
    name: "vibration_scale_device_config_enabled"
+6 −20
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.server.vibrator;

import android.os.SystemClock;
import android.os.VibrationEffect;
import android.os.vibrator.Flags;

import java.util.List;

@@ -54,10 +53,7 @@ abstract class AbstractComposedVibratorStep extends AbstractVibratorStep {
     * current segment from the effect.
     */
    protected List<Step> skipStep() {
        return Flags.vibrationThreadHandlingHalFailure()
                ? skipStep(SystemClock.uptimeMillis())
                // Preserve old behavior when fix is not enabled.
                : vibratorOnNextSteps(/* segmentsPlayed= */ 1);
        return skipStep(SystemClock.uptimeMillis());
    }

    /**
@@ -77,7 +73,6 @@ abstract class AbstractComposedVibratorStep extends AbstractVibratorStep {
     * and it will cancel the playback if the HAL result is unsupported or failure.
     */
    protected List<Step> vibratorOnNextSteps(int segmentsPlayed) {
        if (Flags.vibrationThreadHandlingHalFailure()) {
        if (mVibratorOnResult > 0) {
            // Vibrator was turned on by this step, with mVibratorOnResult as the duration.
            // Schedule next steps for right after the vibration finishes.
@@ -88,15 +83,6 @@ abstract class AbstractComposedVibratorStep extends AbstractVibratorStep {
            return cancelStep();
        }
    }
        // Schedule next steps to run right away.
        long nextStartTime = SystemClock.uptimeMillis();
        if (mVibratorOnResult > 0) {
            // Vibrator was turned on by this step, with mVibratorOnResult as the duration.
            // Schedule next steps for right after the vibration finishes.
            nextStartTime += mVibratorOnResult;
        }
        return nextSteps(nextStartTime, segmentsPlayed);
    }

    /**
     * Return the {@link VibrationStepConductor#nextVibrateStep} with given start time,
+2 −3
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;
@@ -95,7 +94,7 @@ final class SetAmplitudeVibratorStep extends AbstractComposedVibratorStep {
                    long onDuration = getVibratorOnDuration(effect, segmentIndex);
                    if (onDuration > 0) {
                        long vibratorOnResult = startVibrating(onDuration, amplitude);
                        if (Flags.vibrationThreadHandlingHalFailure() && vibratorOnResult <= 0) {
                        if (vibratorOnResult <= 0) {
                            // Error turning vibrator ON, cancel the waveform playback.
                            return cancelStep();
                        }
@@ -125,7 +124,7 @@ final class SetAmplitudeVibratorStep extends AbstractComposedVibratorStep {

            float expectedAmplitude = vibrator.getCurrentAmplitude();
            long vibratorOnResult = startVibrating(onDuration, expectedAmplitude);
            if (Flags.vibrationThreadHandlingHalFailure() && vibratorOnResult <= 0) {
            if (vibratorOnResult <= 0) {
                // Error turning vibrator back ON, cancel the waveform playback.
                return cancelStep();
            }
+9 −19
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import android.annotation.Nullable;
import android.os.Build;
import android.os.CombinedVibration;
import android.os.VibrationEffect;
import android.os.vibrator.Flags;
import android.os.vibrator.PrebakedSegment;
import android.os.vibrator.PrimitiveSegment;
import android.os.vibrator.PwleSegment;
@@ -255,7 +254,6 @@ final class VibrationStepConductor {
            // Vibration still running.
            return null;
        }
        if (Flags.vibrationThreadHandlingHalFailure()) {
        if (mFailedVibratorOnSteps > 0) {
            // Some steps failed to dispatch vibration to the vibrator HAL.
            return new Vibration.EndInfo(Status.IGNORED_ERROR_DISPATCHING);
@@ -266,14 +264,6 @@ final class VibrationStepConductor {
        }
        // No step was successful or failed, nothing played.
        return new Vibration.EndInfo(Status.IGNORED_UNSUPPORTED);
        } else {
            // No pending steps, and something happened.
            if (mSuccessfulVibratorOnSteps > 0) {
                return new Vibration.EndInfo(Status.FINISHED);
            }
            // If no step was able to turn the vibrator ON successfully.
            return new Vibration.EndInfo(Status.IGNORED_UNSUPPORTED);
        }
    }

    /**
+2 −12
Original line number Diff line number Diff line
@@ -222,7 +222,6 @@ public class VibrationThreadTest {
    }

    @Test
    @EnableFlags(Flags.FLAG_VIBRATION_THREAD_HANDLING_HAL_FAILURE)
    public void vibrate_singleVibratorOneShotFailed_doesNotSetAmplitudeAndReturnsFailure() {
        HalVibratorHelper vibratorHelper = mVibratorHelpers.get(VIBRATOR_ID);
        vibratorHelper.setCapabilities(IVibrator.CAP_AMPLITUDE_CONTROL);
@@ -280,7 +279,6 @@ public class VibrationThreadTest {
    }

    @Test
    @EnableFlags(Flags.FLAG_VIBRATION_THREAD_HANDLING_HAL_FAILURE)
    public void vibrate_singleVibratorWaveformFailed_stopsVibrationAfterFailure() {
        HalVibratorHelper vibratorHelper = mVibratorHelpers.get(VIBRATOR_ID);
        vibratorHelper.setCapabilities(IVibrator.CAP_AMPLITUDE_CONTROL);
@@ -830,10 +828,7 @@ public class VibrationThreadTest {
    }

    @Test
    @EnableFlags({
            Flags.FLAG_VENDOR_VIBRATION_EFFECTS,
            Flags.FLAG_VIBRATION_THREAD_HANDLING_HAL_FAILURE,
    })
    @EnableFlags(Flags.FLAG_VENDOR_VIBRATION_EFFECTS)
    public void vibrate_singleVibratorVendorEffectFailed_returnsFailure() {
        HalVibratorHelper vibratorHelper = mVibratorHelpers.get(VIBRATOR_ID);
        vibratorHelper.setCapabilities(IVibrator.CAP_PERFORM_VENDOR_EFFECTS);
@@ -912,7 +907,6 @@ public class VibrationThreadTest {
    }

    @Test
    @EnableFlags(Flags.FLAG_VIBRATION_THREAD_HANDLING_HAL_FAILURE)
    public void vibrate_singleVibratorComposedFailed_returnsFailureAndStopsVibration() {
        HalVibratorHelper vibratorHelper = mVibratorHelpers.get(VIBRATOR_ID);
        vibratorHelper.setCapabilities(IVibrator.CAP_COMPOSE_EFFECTS);
@@ -1246,10 +1240,7 @@ public class VibrationThreadTest {
    }

    @Test
    @EnableFlags({
            Flags.FLAG_NORMALIZED_PWLE_EFFECTS,
            Flags.FLAG_VIBRATION_THREAD_HANDLING_HAL_FAILURE,
    })
    @EnableFlags(Flags.FLAG_NORMALIZED_PWLE_EFFECTS)
    public void vibrate_singleVibratorPwleFailed_returnsFailureAndStopsVibration() {
        HalVibratorHelper vibratorHelper = mVibratorHelpers.get(VIBRATOR_ID);
        vibratorHelper.setCapabilities(IVibrator.CAP_GET_RESONANT_FREQUENCY,
@@ -1671,7 +1662,6 @@ public class VibrationThreadTest {
    }

    @Test
    @EnableFlags(Flags.FLAG_VIBRATION_THREAD_HANDLING_HAL_FAILURE)
    public void vibrate_multipleSyncedOneVibratorFails_returnsFailureAndStopsVibration() {
        int[] vibratorIds = new int[]{1, 2};
        mockVibrators(vibratorIds);