Loading services/core/java/com/android/server/vibrator/VibrationThread.java +23 −18 Original line number Diff line number Diff line Loading @@ -255,9 +255,6 @@ final class VibrationThread extends Thread implements IBinder.DeathRecipient { @Nullable private SingleVibratorStep nextVibrateStep(long startTime, VibratorController controller, VibrationEffect.Composed effect, int segmentIndex, long vibratorOffTimeout) { // Some steps should only start after the vibrator has finished the previous vibration, so // make sure we take the latest between both timings. long latestStartTime = Math.max(startTime, vibratorOffTimeout); if (segmentIndex >= effect.getSegments().size()) { segmentIndex = effect.getRepeatIndex(); } Loading @@ -272,15 +269,14 @@ final class VibrationThread extends Thread implements IBinder.DeathRecipient { VibrationEffectSegment segment = effect.getSegments().get(segmentIndex); if (segment instanceof PrebakedSegment) { return new PerformStep(latestStartTime, controller, effect, segmentIndex, vibratorOffTimeout); return new PerformStep(startTime, controller, effect, segmentIndex, vibratorOffTimeout); } if (segment instanceof PrimitiveSegment) { return new ComposePrimitivesStep(latestStartTime, controller, effect, segmentIndex, return new ComposePrimitivesStep(startTime, controller, effect, segmentIndex, vibratorOffTimeout); } if (segment instanceof RampSegment) { return new ComposePwleStep(latestStartTime, controller, effect, segmentIndex, return new ComposePwleStep(startTime, controller, effect, segmentIndex, vibratorOffTimeout); } return new AmplitudeStep(startTime, controller, effect, segmentIndex, vibratorOffTimeout); Loading Loading @@ -572,7 +568,7 @@ final class VibrationThread extends Thread implements IBinder.DeathRecipient { private long startVibrating(SingleVibratorStep step, List<Step> nextSteps) { nextSteps.addAll(step.play()); long stepDuration = step.getOnResult(); long stepDuration = step.getVibratorOnDuration(); if (stepDuration < 0) { // Step failed, so return negative duration to propagate failure. return stepDuration; Loading Loading @@ -649,14 +645,13 @@ final class VibrationThread extends Thread implements IBinder.DeathRecipient { } /** * Return the result a call to {@link VibratorController#on} method triggered by * {@link #play()}. * Return the duration the vibrator was turned on when this step was played. * * @return A positive duration that the vibrator was turned on for by this step; * Zero if the segment is not supported or vibrator was never turned on; * A negative value if the vibrator call has failed. * Zero if the segment is not supported, the step was not played yet or vibrator was never * turned on by this step; A negative value if the vibrator call has failed. */ public long getOnResult() { public long getVibratorOnDuration() { return mVibratorOnResult; } Loading Loading @@ -690,7 +685,7 @@ final class VibrationThread extends Thread implements IBinder.DeathRecipient { /** * Return the {@link #nextVibrateStep} with same start and off timings calculated from * {@link #getOnResult()}, jumping all played segments. * {@link #getVibratorOnDuration()}, jumping all played segments. * * <p>This method has same behavior as {@link #skipToNextSteps(int)} when the vibrator * result is non-positive, meaning the vibrator has either ignored or failed to turn on. Loading Loading @@ -730,7 +725,10 @@ final class VibrationThread extends Thread implements IBinder.DeathRecipient { PerformStep(long startTime, VibratorController controller, VibrationEffect.Composed effect, int index, long vibratorOffTimeout) { super(startTime, controller, effect, index, vibratorOffTimeout); // This step should wait for the last vibration to finish (with the timeout) and for the // intended step start time (to respect the effect delays). super(Math.max(startTime, vibratorOffTimeout), controller, effect, index, vibratorOffTimeout); } @Override Loading Loading @@ -765,7 +763,7 @@ final class VibrationThread extends Thread implements IBinder.DeathRecipient { List<Step> fallbackResult = fallbackStep.play(); // Update the result with the fallback result so this step is seamlessly // replaced by the fallback to any outer application of this. mVibratorOnResult = fallbackStep.getOnResult(); mVibratorOnResult = fallbackStep.getVibratorOnDuration(); return fallbackResult; } Loading Loading @@ -802,7 +800,10 @@ final class VibrationThread extends Thread implements IBinder.DeathRecipient { ComposePrimitivesStep(long startTime, VibratorController controller, VibrationEffect.Composed effect, int index, long vibratorOffTimeout) { super(startTime, controller, effect, index, vibratorOffTimeout); // This step should wait for the last vibration to finish (with the timeout) and for the // intended step start time (to respect the effect delays). super(Math.max(startTime, vibratorOffTimeout), controller, effect, index, vibratorOffTimeout); } @Override Loading Loading @@ -851,7 +852,10 @@ final class VibrationThread extends Thread implements IBinder.DeathRecipient { ComposePwleStep(long startTime, VibratorController controller, VibrationEffect.Composed effect, int index, long vibratorOffTimeout) { super(startTime, controller, effect, index, vibratorOffTimeout); // This step should wait for the last vibration to finish (with the timeout) and for the // intended step start time (to respect the effect delays). super(Math.max(startTime, vibratorOffTimeout), controller, effect, index, vibratorOffTimeout); } @Override Loading Loading @@ -924,6 +928,7 @@ final class VibrationThread extends Thread implements IBinder.DeathRecipient { AmplitudeStep(long startTime, VibratorController controller, VibrationEffect.Composed effect, int index, long vibratorOffTimeout) { // This step has a fixed startTime coming from the timings of the waveform it's playing. super(startTime, controller, effect, index, vibratorOffTimeout); mNextOffTime = vibratorOffTimeout; } Loading services/core/jni/com_android_server_vibrator_VibratorController.cpp +12 −12 Original line number Diff line number Diff line Loading @@ -199,7 +199,7 @@ static jboolean vibratorIsAvailable(JNIEnv* env, jclass /* clazz */, jlong ptr) ALOGE("vibratorIsAvailable failed because native wrapper was not initialized"); return JNI_FALSE; } auto pingFn = [](std::shared_ptr<vibrator::HalWrapper> hal) { return hal->ping(); }; auto pingFn = [](vibrator::HalWrapper* hal) { return hal->ping(); }; return wrapper->halCall<void>(pingFn, "ping").isOk() ? JNI_TRUE : JNI_FALSE; } Loading @@ -211,7 +211,7 @@ static jlong vibratorOn(JNIEnv* env, jclass /* clazz */, jlong ptr, jlong timeou return -1; } auto callback = wrapper->createCallback(vibrationId); auto onFn = [&](std::shared_ptr<vibrator::HalWrapper> hal) { auto onFn = [timeoutMs, &callback](vibrator::HalWrapper* hal) { return hal->on(std::chrono::milliseconds(timeoutMs), callback); }; auto result = wrapper->halCall<void>(onFn, "on"); Loading @@ -224,7 +224,7 @@ static void vibratorOff(JNIEnv* env, jclass /* clazz */, jlong ptr) { ALOGE("vibratorOff failed because native wrapper was not initialized"); return; } auto offFn = [](std::shared_ptr<vibrator::HalWrapper> hal) { return hal->off(); }; auto offFn = [](vibrator::HalWrapper* hal) { return hal->off(); }; wrapper->halCall<void>(offFn, "off"); } Loading @@ -234,7 +234,7 @@ static void vibratorSetAmplitude(JNIEnv* env, jclass /* clazz */, jlong ptr, jfl ALOGE("vibratorSetAmplitude failed because native wrapper was not initialized"); return; } auto setAmplitudeFn = [&](std::shared_ptr<vibrator::HalWrapper> hal) { auto setAmplitudeFn = [amplitude](vibrator::HalWrapper* hal) { return hal->setAmplitude(static_cast<float>(amplitude)); }; wrapper->halCall<void>(setAmplitudeFn, "setAmplitude"); Loading @@ -247,7 +247,7 @@ static void vibratorSetExternalControl(JNIEnv* env, jclass /* clazz */, jlong pt ALOGE("vibratorSetExternalControl failed because native wrapper was not initialized"); return; } auto setExternalControlFn = [&](std::shared_ptr<vibrator::HalWrapper> hal) { auto setExternalControlFn = [enabled](vibrator::HalWrapper* hal) { return hal->setExternalControl(enabled); }; wrapper->halCall<void>(setExternalControlFn, "setExternalControl"); Loading @@ -263,7 +263,7 @@ static jlong vibratorPerformEffect(JNIEnv* env, jclass /* clazz */, jlong ptr, j aidl::Effect effectType = static_cast<aidl::Effect>(effect); aidl::EffectStrength effectStrength = static_cast<aidl::EffectStrength>(strength); auto callback = wrapper->createCallback(vibrationId); auto performEffectFn = [&](std::shared_ptr<vibrator::HalWrapper> hal) { auto performEffectFn = [effectType, effectStrength, &callback](vibrator::HalWrapper* hal) { return hal->performEffect(effectType, effectStrength, callback); }; auto result = wrapper->halCall<std::chrono::milliseconds>(performEffectFn, "performEffect"); Loading @@ -284,7 +284,7 @@ static jlong vibratorPerformComposedEffect(JNIEnv* env, jclass /* clazz */, jlon effects.push_back(effectFromJavaPrimitive(env, element)); } auto callback = wrapper->createCallback(vibrationId); auto performComposedEffectFn = [&](std::shared_ptr<vibrator::HalWrapper> hal) { auto performComposedEffectFn = [&effects, &callback](vibrator::HalWrapper* hal) { return hal->performComposedEffect(effects, callback); }; auto result = wrapper->halCall<std::chrono::milliseconds>(performComposedEffectFn, Loading Loading @@ -319,7 +319,7 @@ static jlong vibratorPerformPwleEffect(JNIEnv* env, jclass /* clazz */, jlong pt } auto callback = wrapper->createCallback(vibrationId); auto performPwleEffectFn = [&](std::shared_ptr<vibrator::HalWrapper> hal) { auto performPwleEffectFn = [&primitives, &callback](vibrator::HalWrapper* hal) { return hal->performPwleEffect(primitives, callback); }; auto result = wrapper->halCall<void>(performPwleEffectFn, "performPwleEffect"); Loading @@ -333,7 +333,7 @@ static void vibratorAlwaysOnEnable(JNIEnv* env, jclass /* clazz */, jlong ptr, j ALOGE("vibratorAlwaysOnEnable failed because native wrapper was not initialized"); return; } auto alwaysOnEnableFn = [&](std::shared_ptr<vibrator::HalWrapper> hal) { auto alwaysOnEnableFn = [id, effect, strength](vibrator::HalWrapper* hal) { return hal->alwaysOnEnable(static_cast<int32_t>(id), static_cast<aidl::Effect>(effect), static_cast<aidl::EffectStrength>(strength)); }; Loading @@ -346,7 +346,7 @@ static void vibratorAlwaysOnDisable(JNIEnv* env, jclass /* clazz */, jlong ptr, ALOGE("vibratorAlwaysOnDisable failed because native wrapper was not initialized"); return; } auto alwaysOnDisableFn = [&](std::shared_ptr<vibrator::HalWrapper> hal) { auto alwaysOnDisableFn = [id](vibrator::HalWrapper* hal) { return hal->alwaysOnDisable(static_cast<int32_t>(id)); }; wrapper->halCall<void>(alwaysOnDisableFn, "alwaysOnDisable"); Loading Loading @@ -446,11 +446,11 @@ int register_android_server_vibrator_VibratorController(JavaVM* jvm, JNIEnv* env sRampClassInfo.duration = GetFieldIDOrDie(env, rampClass, "mDuration", "I"); jclass frequencyMappingClass = FindClassOrDie(env, "android/os/VibratorInfo$FrequencyMapping"); sFrequencyMappingClass = (jclass)env->NewGlobalRef(frequencyMappingClass); sFrequencyMappingClass = static_cast<jclass>(env->NewGlobalRef(frequencyMappingClass)); sFrequencyMappingCtor = GetMethodIDOrDie(env, sFrequencyMappingClass, "<init>", "(FFFF[F)V"); jclass vibratorInfoClass = FindClassOrDie(env, "android/os/VibratorInfo"); sVibratorInfoClass = (jclass)env->NewGlobalRef(vibratorInfoClass); sVibratorInfoClass = static_cast<jclass>(env->NewGlobalRef(vibratorInfoClass)); sVibratorInfoCtor = GetMethodIDOrDie(env, sVibratorInfoClass, "<init>", "(IJ[I[I[IFLandroid/os/VibratorInfo$FrequencyMapping;)V"); Loading Loading
services/core/java/com/android/server/vibrator/VibrationThread.java +23 −18 Original line number Diff line number Diff line Loading @@ -255,9 +255,6 @@ final class VibrationThread extends Thread implements IBinder.DeathRecipient { @Nullable private SingleVibratorStep nextVibrateStep(long startTime, VibratorController controller, VibrationEffect.Composed effect, int segmentIndex, long vibratorOffTimeout) { // Some steps should only start after the vibrator has finished the previous vibration, so // make sure we take the latest between both timings. long latestStartTime = Math.max(startTime, vibratorOffTimeout); if (segmentIndex >= effect.getSegments().size()) { segmentIndex = effect.getRepeatIndex(); } Loading @@ -272,15 +269,14 @@ final class VibrationThread extends Thread implements IBinder.DeathRecipient { VibrationEffectSegment segment = effect.getSegments().get(segmentIndex); if (segment instanceof PrebakedSegment) { return new PerformStep(latestStartTime, controller, effect, segmentIndex, vibratorOffTimeout); return new PerformStep(startTime, controller, effect, segmentIndex, vibratorOffTimeout); } if (segment instanceof PrimitiveSegment) { return new ComposePrimitivesStep(latestStartTime, controller, effect, segmentIndex, return new ComposePrimitivesStep(startTime, controller, effect, segmentIndex, vibratorOffTimeout); } if (segment instanceof RampSegment) { return new ComposePwleStep(latestStartTime, controller, effect, segmentIndex, return new ComposePwleStep(startTime, controller, effect, segmentIndex, vibratorOffTimeout); } return new AmplitudeStep(startTime, controller, effect, segmentIndex, vibratorOffTimeout); Loading Loading @@ -572,7 +568,7 @@ final class VibrationThread extends Thread implements IBinder.DeathRecipient { private long startVibrating(SingleVibratorStep step, List<Step> nextSteps) { nextSteps.addAll(step.play()); long stepDuration = step.getOnResult(); long stepDuration = step.getVibratorOnDuration(); if (stepDuration < 0) { // Step failed, so return negative duration to propagate failure. return stepDuration; Loading Loading @@ -649,14 +645,13 @@ final class VibrationThread extends Thread implements IBinder.DeathRecipient { } /** * Return the result a call to {@link VibratorController#on} method triggered by * {@link #play()}. * Return the duration the vibrator was turned on when this step was played. * * @return A positive duration that the vibrator was turned on for by this step; * Zero if the segment is not supported or vibrator was never turned on; * A negative value if the vibrator call has failed. * Zero if the segment is not supported, the step was not played yet or vibrator was never * turned on by this step; A negative value if the vibrator call has failed. */ public long getOnResult() { public long getVibratorOnDuration() { return mVibratorOnResult; } Loading Loading @@ -690,7 +685,7 @@ final class VibrationThread extends Thread implements IBinder.DeathRecipient { /** * Return the {@link #nextVibrateStep} with same start and off timings calculated from * {@link #getOnResult()}, jumping all played segments. * {@link #getVibratorOnDuration()}, jumping all played segments. * * <p>This method has same behavior as {@link #skipToNextSteps(int)} when the vibrator * result is non-positive, meaning the vibrator has either ignored or failed to turn on. Loading Loading @@ -730,7 +725,10 @@ final class VibrationThread extends Thread implements IBinder.DeathRecipient { PerformStep(long startTime, VibratorController controller, VibrationEffect.Composed effect, int index, long vibratorOffTimeout) { super(startTime, controller, effect, index, vibratorOffTimeout); // This step should wait for the last vibration to finish (with the timeout) and for the // intended step start time (to respect the effect delays). super(Math.max(startTime, vibratorOffTimeout), controller, effect, index, vibratorOffTimeout); } @Override Loading Loading @@ -765,7 +763,7 @@ final class VibrationThread extends Thread implements IBinder.DeathRecipient { List<Step> fallbackResult = fallbackStep.play(); // Update the result with the fallback result so this step is seamlessly // replaced by the fallback to any outer application of this. mVibratorOnResult = fallbackStep.getOnResult(); mVibratorOnResult = fallbackStep.getVibratorOnDuration(); return fallbackResult; } Loading Loading @@ -802,7 +800,10 @@ final class VibrationThread extends Thread implements IBinder.DeathRecipient { ComposePrimitivesStep(long startTime, VibratorController controller, VibrationEffect.Composed effect, int index, long vibratorOffTimeout) { super(startTime, controller, effect, index, vibratorOffTimeout); // This step should wait for the last vibration to finish (with the timeout) and for the // intended step start time (to respect the effect delays). super(Math.max(startTime, vibratorOffTimeout), controller, effect, index, vibratorOffTimeout); } @Override Loading Loading @@ -851,7 +852,10 @@ final class VibrationThread extends Thread implements IBinder.DeathRecipient { ComposePwleStep(long startTime, VibratorController controller, VibrationEffect.Composed effect, int index, long vibratorOffTimeout) { super(startTime, controller, effect, index, vibratorOffTimeout); // This step should wait for the last vibration to finish (with the timeout) and for the // intended step start time (to respect the effect delays). super(Math.max(startTime, vibratorOffTimeout), controller, effect, index, vibratorOffTimeout); } @Override Loading Loading @@ -924,6 +928,7 @@ final class VibrationThread extends Thread implements IBinder.DeathRecipient { AmplitudeStep(long startTime, VibratorController controller, VibrationEffect.Composed effect, int index, long vibratorOffTimeout) { // This step has a fixed startTime coming from the timings of the waveform it's playing. super(startTime, controller, effect, index, vibratorOffTimeout); mNextOffTime = vibratorOffTimeout; } Loading
services/core/jni/com_android_server_vibrator_VibratorController.cpp +12 −12 Original line number Diff line number Diff line Loading @@ -199,7 +199,7 @@ static jboolean vibratorIsAvailable(JNIEnv* env, jclass /* clazz */, jlong ptr) ALOGE("vibratorIsAvailable failed because native wrapper was not initialized"); return JNI_FALSE; } auto pingFn = [](std::shared_ptr<vibrator::HalWrapper> hal) { return hal->ping(); }; auto pingFn = [](vibrator::HalWrapper* hal) { return hal->ping(); }; return wrapper->halCall<void>(pingFn, "ping").isOk() ? JNI_TRUE : JNI_FALSE; } Loading @@ -211,7 +211,7 @@ static jlong vibratorOn(JNIEnv* env, jclass /* clazz */, jlong ptr, jlong timeou return -1; } auto callback = wrapper->createCallback(vibrationId); auto onFn = [&](std::shared_ptr<vibrator::HalWrapper> hal) { auto onFn = [timeoutMs, &callback](vibrator::HalWrapper* hal) { return hal->on(std::chrono::milliseconds(timeoutMs), callback); }; auto result = wrapper->halCall<void>(onFn, "on"); Loading @@ -224,7 +224,7 @@ static void vibratorOff(JNIEnv* env, jclass /* clazz */, jlong ptr) { ALOGE("vibratorOff failed because native wrapper was not initialized"); return; } auto offFn = [](std::shared_ptr<vibrator::HalWrapper> hal) { return hal->off(); }; auto offFn = [](vibrator::HalWrapper* hal) { return hal->off(); }; wrapper->halCall<void>(offFn, "off"); } Loading @@ -234,7 +234,7 @@ static void vibratorSetAmplitude(JNIEnv* env, jclass /* clazz */, jlong ptr, jfl ALOGE("vibratorSetAmplitude failed because native wrapper was not initialized"); return; } auto setAmplitudeFn = [&](std::shared_ptr<vibrator::HalWrapper> hal) { auto setAmplitudeFn = [amplitude](vibrator::HalWrapper* hal) { return hal->setAmplitude(static_cast<float>(amplitude)); }; wrapper->halCall<void>(setAmplitudeFn, "setAmplitude"); Loading @@ -247,7 +247,7 @@ static void vibratorSetExternalControl(JNIEnv* env, jclass /* clazz */, jlong pt ALOGE("vibratorSetExternalControl failed because native wrapper was not initialized"); return; } auto setExternalControlFn = [&](std::shared_ptr<vibrator::HalWrapper> hal) { auto setExternalControlFn = [enabled](vibrator::HalWrapper* hal) { return hal->setExternalControl(enabled); }; wrapper->halCall<void>(setExternalControlFn, "setExternalControl"); Loading @@ -263,7 +263,7 @@ static jlong vibratorPerformEffect(JNIEnv* env, jclass /* clazz */, jlong ptr, j aidl::Effect effectType = static_cast<aidl::Effect>(effect); aidl::EffectStrength effectStrength = static_cast<aidl::EffectStrength>(strength); auto callback = wrapper->createCallback(vibrationId); auto performEffectFn = [&](std::shared_ptr<vibrator::HalWrapper> hal) { auto performEffectFn = [effectType, effectStrength, &callback](vibrator::HalWrapper* hal) { return hal->performEffect(effectType, effectStrength, callback); }; auto result = wrapper->halCall<std::chrono::milliseconds>(performEffectFn, "performEffect"); Loading @@ -284,7 +284,7 @@ static jlong vibratorPerformComposedEffect(JNIEnv* env, jclass /* clazz */, jlon effects.push_back(effectFromJavaPrimitive(env, element)); } auto callback = wrapper->createCallback(vibrationId); auto performComposedEffectFn = [&](std::shared_ptr<vibrator::HalWrapper> hal) { auto performComposedEffectFn = [&effects, &callback](vibrator::HalWrapper* hal) { return hal->performComposedEffect(effects, callback); }; auto result = wrapper->halCall<std::chrono::milliseconds>(performComposedEffectFn, Loading Loading @@ -319,7 +319,7 @@ static jlong vibratorPerformPwleEffect(JNIEnv* env, jclass /* clazz */, jlong pt } auto callback = wrapper->createCallback(vibrationId); auto performPwleEffectFn = [&](std::shared_ptr<vibrator::HalWrapper> hal) { auto performPwleEffectFn = [&primitives, &callback](vibrator::HalWrapper* hal) { return hal->performPwleEffect(primitives, callback); }; auto result = wrapper->halCall<void>(performPwleEffectFn, "performPwleEffect"); Loading @@ -333,7 +333,7 @@ static void vibratorAlwaysOnEnable(JNIEnv* env, jclass /* clazz */, jlong ptr, j ALOGE("vibratorAlwaysOnEnable failed because native wrapper was not initialized"); return; } auto alwaysOnEnableFn = [&](std::shared_ptr<vibrator::HalWrapper> hal) { auto alwaysOnEnableFn = [id, effect, strength](vibrator::HalWrapper* hal) { return hal->alwaysOnEnable(static_cast<int32_t>(id), static_cast<aidl::Effect>(effect), static_cast<aidl::EffectStrength>(strength)); }; Loading @@ -346,7 +346,7 @@ static void vibratorAlwaysOnDisable(JNIEnv* env, jclass /* clazz */, jlong ptr, ALOGE("vibratorAlwaysOnDisable failed because native wrapper was not initialized"); return; } auto alwaysOnDisableFn = [&](std::shared_ptr<vibrator::HalWrapper> hal) { auto alwaysOnDisableFn = [id](vibrator::HalWrapper* hal) { return hal->alwaysOnDisable(static_cast<int32_t>(id)); }; wrapper->halCall<void>(alwaysOnDisableFn, "alwaysOnDisable"); Loading Loading @@ -446,11 +446,11 @@ int register_android_server_vibrator_VibratorController(JavaVM* jvm, JNIEnv* env sRampClassInfo.duration = GetFieldIDOrDie(env, rampClass, "mDuration", "I"); jclass frequencyMappingClass = FindClassOrDie(env, "android/os/VibratorInfo$FrequencyMapping"); sFrequencyMappingClass = (jclass)env->NewGlobalRef(frequencyMappingClass); sFrequencyMappingClass = static_cast<jclass>(env->NewGlobalRef(frequencyMappingClass)); sFrequencyMappingCtor = GetMethodIDOrDie(env, sFrequencyMappingClass, "<init>", "(FFFF[F)V"); jclass vibratorInfoClass = FindClassOrDie(env, "android/os/VibratorInfo"); sVibratorInfoClass = (jclass)env->NewGlobalRef(vibratorInfoClass); sVibratorInfoClass = static_cast<jclass>(env->NewGlobalRef(vibratorInfoClass)); sVibratorInfoCtor = GetMethodIDOrDie(env, sVibratorInfoClass, "<init>", "(IJ[I[I[IFLandroid/os/VibratorInfo$FrequencyMapping;)V"); Loading