diff options
| author | 2020-02-13 15:53:08 +0900 | |
|---|---|---|
| committer | 2020-02-26 19:02:30 +0000 | |
| commit | 3e7613d16ef96a05dc70a28e81d0f79bbf7ced36 (patch) | |
| tree | 4244aa6378e92ccd21c5e1e3f0f7c09ad29c1939 | |
| parent | 2f6d575468902a7b85bcb292f28f0c9605972a24 (diff) | |
VibratorService: Conditionally Use Callbacks
VTS is enforcing that HALs return error if the callback is not null and
callbacks are not supported.
Bug: 137601983
Test: Manually on devices with and without callback support.
Change-Id: Iada3a4189f8e0986e7894f4bcdc3d9c309d313d8
Signed-off-by: Harpreet \"Eli\" Sangha <eliptus@google.com>
| -rw-r--r-- | services/core/java/com/android/server/VibratorService.java | 6 | ||||
| -rw-r--r-- | services/core/jni/com_android_server_VibratorService.cpp | 41 | 
2 files changed, 25 insertions, 22 deletions
| diff --git a/services/core/java/com/android/server/VibratorService.java b/services/core/java/com/android/server/VibratorService.java index 0f1a6520ed4f..dd9cc641f2dd 100644 --- a/services/core/java/com/android/server/VibratorService.java +++ b/services/core/java/com/android/server/VibratorService.java @@ -183,7 +183,8 @@ public class VibratorService extends IVibratorService.Stub      static native boolean vibratorSupportsAmplitudeControl();      static native void vibratorSetAmplitude(int amplitude);      static native int[] vibratorGetSupportedEffects(); -    static native long vibratorPerformEffect(long effect, long strength, Vibration vibration); +    static native long vibratorPerformEffect(long effect, long strength, Vibration vibration, +            boolean withCallback);      static native void vibratorPerformComposedEffect(              VibrationEffect.Composition.PrimitiveEffect[] effect, Vibration vibration);      static native boolean vibratorSupportsExternalControl(); @@ -1334,7 +1335,8 @@ public class VibratorService extends IVibratorService.Stub              // Input devices don't support prebaked effect, so skip trying it with them.              if (!usingInputDeviceVibrators) {                  long duration = vibratorPerformEffect(prebaked.getId(), -                        prebaked.getEffectStrength(), vib); +                        prebaked.getEffectStrength(), vib, +                        hasCapability(IVibrator.CAP_PERFORM_CALLBACK));                  long timeout = duration;                  if (hasCapability(IVibrator.CAP_PERFORM_CALLBACK)) {                      timeout *= ASYNC_TIMEOUT_MULTIPLIER; diff --git a/services/core/jni/com_android_server_VibratorService.cpp b/services/core/jni/com_android_server_VibratorService.cpp index 5a8e25e4cf1c..05aa3594eb68 100644 --- a/services/core/jni/com_android_server_VibratorService.cpp +++ b/services/core/jni/com_android_server_VibratorService.cpp @@ -355,10 +355,11 @@ static jintArray vibratorGetSupportedEffects(JNIEnv *env, jclass) {  }  static jlong vibratorPerformEffect(JNIEnv* env, jclass, jlong effect, jlong strength, -                                   jobject vibration) { +                                   jobject vibration, jboolean withCallback) {      if (auto hal = getHal<aidl::IVibrator>()) {          int32_t lengthMs; -        sp<AidlVibratorCallback> effectCallback = new AidlVibratorCallback(env, vibration); +        sp<AidlVibratorCallback> effectCallback = +                (withCallback != JNI_FALSE ? new AidlVibratorCallback(env, vibration) : nullptr);          aidl::Effect effectType(static_cast<aidl::Effect>(effect));          aidl::EffectStrength effectStrength(static_cast<aidl::EffectStrength>(strength)); @@ -478,24 +479,24 @@ static void vibratorAlwaysOnDisable(JNIEnv* env, jclass, jlong id) {  }  static const JNINativeMethod method_table[] = { -    { "vibratorExists", "()Z", (void*)vibratorExists }, -    { "vibratorInit", "()V", (void*)vibratorInit }, -    { "vibratorOn", "(J)V", (void*)vibratorOn }, -    { "vibratorOff", "()V", (void*)vibratorOff }, -    { "vibratorSupportsAmplitudeControl", "()Z", (void*)vibratorSupportsAmplitudeControl}, -    { "vibratorSetAmplitude", "(I)V", (void*)vibratorSetAmplitude}, -    { "vibratorPerformEffect", "(JJLcom/android/server/VibratorService$Vibration;)J", -            (void*)vibratorPerformEffect}, -    { "vibratorPerformComposedEffect", -            "([Landroid/os/VibrationEffect$Composition$PrimitiveEffect;Lcom/android/server/VibratorService$Vibration;)V", -            (void*)vibratorPerformComposedEffect}, -    { "vibratorGetSupportedEffects", "()[I", -            (void*)vibratorGetSupportedEffects}, -    { "vibratorSupportsExternalControl", "()Z", (void*)vibratorSupportsExternalControl}, -    { "vibratorSetExternalControl", "(Z)V", (void*)vibratorSetExternalControl}, -    { "vibratorGetCapabilities", "()J", (void*)vibratorGetCapabilities}, -    { "vibratorAlwaysOnEnable", "(JJJ)V", (void*)vibratorAlwaysOnEnable}, -    { "vibratorAlwaysOnDisable", "(J)V", (void*)vibratorAlwaysOnDisable}, +        {"vibratorExists", "()Z", (void*)vibratorExists}, +        {"vibratorInit", "()V", (void*)vibratorInit}, +        {"vibratorOn", "(J)V", (void*)vibratorOn}, +        {"vibratorOff", "()V", (void*)vibratorOff}, +        {"vibratorSupportsAmplitudeControl", "()Z", (void*)vibratorSupportsAmplitudeControl}, +        {"vibratorSetAmplitude", "(I)V", (void*)vibratorSetAmplitude}, +        {"vibratorPerformEffect", "(JJLcom/android/server/VibratorService$Vibration;Z)J", +         (void*)vibratorPerformEffect}, +        {"vibratorPerformComposedEffect", +         "([Landroid/os/VibrationEffect$Composition$PrimitiveEffect;Lcom/android/server/" +         "VibratorService$Vibration;)V", +         (void*)vibratorPerformComposedEffect}, +        {"vibratorGetSupportedEffects", "()[I", (void*)vibratorGetSupportedEffects}, +        {"vibratorSupportsExternalControl", "()Z", (void*)vibratorSupportsExternalControl}, +        {"vibratorSetExternalControl", "(Z)V", (void*)vibratorSetExternalControl}, +        {"vibratorGetCapabilities", "()J", (void*)vibratorGetCapabilities}, +        {"vibratorAlwaysOnEnable", "(JJJ)V", (void*)vibratorAlwaysOnEnable}, +        {"vibratorAlwaysOnDisable", "(J)V", (void*)vibratorAlwaysOnDisable},  };  int register_android_server_VibratorService(JNIEnv *env) { |