vibrator: Properly enable strength control

Change-Id: Icc17b07e48b0bb4d5886998f9f75f22c7bd3fa3f
diff --git a/aidl/vibrator/Vibrator.cpp b/aidl/vibrator/Vibrator.cpp
index 57570f0..134ba4e 100644
--- a/aidl/vibrator/Vibrator.cpp
+++ b/aidl/vibrator/Vibrator.cpp
@@ -85,13 +85,7 @@
     if (vibStrengths.find(strength) == vibStrengths.end())
         return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION));
 
-    if (mVibratorStrengthSupported) {
-        // Vibration strength is relative to the max strength reported by the kernel.
-        int vib_strength = static_cast<int>(mVibratorStrengthMax * vibStrengths[strength] / 10.0 + 0.5);
-        status = setNode(kVibratorStrength, vib_strength);
-        if (!status.isOk())
-            return status;
-    }
+    setAmplitude(vibStrengths[strength]);
 
     timeoutMs = vibEffects[effect];
 
@@ -128,8 +122,27 @@
     return ndk::ScopedAStatus::ok();
 }
 
+#ifdef VIBRATOR_SUPPORTS_EFFECTS
+ndk::ScopedAStatus Vibrator::setAmplitude(float amplitude) {
+    int32_t intensity;
+
+    if (amplitude <= 0.0f || amplitude > 1.0f)
+        return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_ILLEGAL_ARGUMENT));
+
+    LOG(VERBOSE) << "Setting amplitude: " << amplitude;
+
+    intensity = amplitude * mVibratorStrengthMax;
+
+    LOG(VERBOSE) << "Setting intensity: " << intensity;
+
+    if (mVibratorStrengthSupported)
+        setNode(kVibratorStrength, intensity);
+
+    return ndk::ScopedAStatus::ok();
+#else
 ndk::ScopedAStatus Vibrator::setAmplitude(float amplitude __unused) {
     return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION));
+#endif
 }
 
 ndk::ScopedAStatus Vibrator::setExternalControl(bool enabled __unused) {
diff --git a/aidl/vibrator/Vibrator.h b/aidl/vibrator/Vibrator.h
index 32b7e7f..f64d49a 100644
--- a/aidl/vibrator/Vibrator.h
+++ b/aidl/vibrator/Vibrator.h
@@ -40,10 +40,10 @@
     { Effect::TICK, 32 }
 };
 
-static std::map<EffectStrength, int32_t> vibStrengths = {
-    { EffectStrength::LIGHT, 4},
-    { EffectStrength::MEDIUM, 6},
-    { EffectStrength::STRONG, 10}
+static std::map<EffectStrength, float> vibStrengths = {
+    { EffectStrength::LIGHT, 0.25 },
+    { EffectStrength::MEDIUM, 0.5 },
+    { EffectStrength::STRONG, 1 }
 };
 #endif