From 3e8e6599972bf8fd48c832dbd5ba6214e0b2cefc Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Mon, 29 Jan 2018 14:54:37 +0000 Subject: [PATCH] Upgrade vibrator to HAL 1.2 Bug: 64184692 Test: build, flash and play with device Change-Id: I44d82371e6a6d7dc7e05e740aa5f2fdb5c3f8df6 --- CleanSpec.mk | 4 ++ device.mk | 2 +- manifest.xml | 2 +- sepolicy/vendor/file_contexts | 2 +- vibrator/Android.bp | 5 +- vibrator/Vibrator.cpp | 57 +++++++++---------- vibrator/Vibrator.h | 21 ++++--- ...oid.hardware.vibrator@1.1-service.wahoo.rc | 4 -- ...oid.hardware.vibrator@1.2-service.wahoo.rc | 4 ++ vibrator/service.cpp | 8 +-- 10 files changed, 57 insertions(+), 52 deletions(-) delete mode 100644 vibrator/android.hardware.vibrator@1.1-service.wahoo.rc create mode 100644 vibrator/android.hardware.vibrator@1.2-service.wahoo.rc diff --git a/CleanSpec.mk b/CleanSpec.mk index c105dba8..b0c4379e 100644 --- a/CleanSpec.mk +++ b/CleanSpec.mk @@ -164,3 +164,7 @@ $(call add-clean-step, rm -rf $(PRODUCT_OUT)/vendor/etc/init/android.hardware.he # Remove PowerHAL $(call add-clean-step, rm -rf $(PRODUCT_OUT)/vendor/etc/init/android.hardware.power*) $(call add-clean-step, rm -rf $(PRODUCT_OUT)/vendor/bin/hw/android.hardware.power*) + +# Remove Vibrator HAL 1.1 +$(call add-clean-step, rm -rf $(PRODUCT_OUT)/vendor/etc/init/android.hardware.vibrator@1.1-service.wahoo.rc) +$(call add-clean-step, rm -rf $(PRODUCT_OUT)/vendor/bin/hw/android.hardware.vibrator@1.1-service.wahoo) diff --git a/device.mk b/device.mk index 64fa0521..38c6cdb0 100755 --- a/device.mk +++ b/device.mk @@ -402,7 +402,7 @@ PRODUCT_PACKAGES += \ # Vibrator HAL PRODUCT_PACKAGES += \ - android.hardware.vibrator@1.1-service.wahoo + android.hardware.vibrator@1.2-service.wahoo # Thermal packages PRODUCT_PACKAGES += \ diff --git a/manifest.xml b/manifest.xml index ca6f6c7f..132d0d19 100644 --- a/manifest.xml +++ b/manifest.xml @@ -342,7 +342,7 @@ android.hardware.vibrator hwbinder - 1.1 + 1.2 IVibrator default diff --git a/sepolicy/vendor/file_contexts b/sepolicy/vendor/file_contexts index b7a01b76..e4ab3a9b 100644 --- a/sepolicy/vendor/file_contexts +++ b/sepolicy/vendor/file_contexts @@ -186,7 +186,7 @@ /vendor/bin/hw/android\.hardware\.drm@1\.0-service\.widevine u:object_r:hal_drm_widevine_exec:s0 /vendor/bin/hw/android\.hardware\.drm@1\.1-service\.clearkey u:object_r:hal_drm_clearkey_exec:s0 -/vendor/bin/hw/android\.hardware\.vibrator@1\.1-service\.wahoo u:object_r:hal_vibrator_default_exec:s0 +/vendor/bin/hw/android\.hardware\.vibrator@1\.2-service\.wahoo u:object_r:hal_vibrator_default_exec:s0 /vendor/bin/hw/android\.hardware\.health@2\.0-service\.wahoo u:object_r:hal_health_default_exec:s0 /vendor/bin/hw/android\.hardware\.keymaster@3\.0-service-qti u:object_r:hal_keymaster_qti_exec:s0 /vendor/bin/hw/android\.hardware\.gatekeeper@1\.0-service-qti u:object_r:hal_gatekeeper_qti_exec:s0 diff --git a/vibrator/Android.bp b/vibrator/Android.bp index b4f5fa7d..c02ae54e 100644 --- a/vibrator/Android.bp +++ b/vibrator/Android.bp @@ -13,9 +13,9 @@ // See the License for the specific language governing permissions and // limitations under the License. cc_binary { - name: "android.hardware.vibrator@1.1-service.wahoo", + name: "android.hardware.vibrator@1.2-service.wahoo", relative_install_path: "hw", - init_rc: ["android.hardware.vibrator@1.1-service.wahoo.rc"], + init_rc: ["android.hardware.vibrator@1.2-service.wahoo.rc"], srcs: ["service.cpp", "Vibrator.cpp"], cflags: [ "-Wall", @@ -31,6 +31,7 @@ cc_binary { "libhardware", "android.hardware.vibrator@1.0", "android.hardware.vibrator@1.1", + "android.hardware.vibrator@1.2", ], proprietary: true, } diff --git a/vibrator/Vibrator.cpp b/vibrator/Vibrator.cpp index db64bb13..20ae48b0 100644 --- a/vibrator/Vibrator.cpp +++ b/vibrator/Vibrator.cpp @@ -33,7 +33,7 @@ namespace android { namespace hardware { namespace vibrator { -namespace V1_1 { +namespace V1_2 { namespace implementation { static constexpr int8_t MAX_RTP_INPUT = 127; @@ -116,7 +116,7 @@ Return Vibrator::on(uint32_t timeoutMs, bool forceOpenLoop, bool isWavef return Status::OK; } -// Methods from ::android::hardware::vibrator::V1_1::IVibrator follow. +// Methods from ::android::hardware::vibrator::V1_2::IVibrator follow. Return Vibrator::on(uint32_t timeoutMs) { return on(timeoutMs, false /* forceOpenLoop */, false /* isWaveform */); } @@ -158,7 +158,7 @@ static uint8_t convertEffectStrength(EffectStrength strength) { switch (strength) { case EffectStrength::LIGHT: - scale = 1; // 50% + scale = 2; // 50% break; case EffectStrength::MEDIUM: case EffectStrength::STRONG: @@ -169,52 +169,49 @@ static uint8_t convertEffectStrength(EffectStrength strength) { return scale; } -Return Vibrator::perform(Effect effect, EffectStrength strength, perform_cb _hidl_cb) { +Return Vibrator::perform(V1_0::Effect effect, EffectStrength strength, perform_cb _hidl_cb) { + return performEffect(static_cast(effect), strength, _hidl_cb); +} + +Return Vibrator::perform_1_1(V1_1::Effect_1_1 effect, EffectStrength strength, + perform_cb _hidl_cb) { + return performEffect(static_cast(effect), strength, _hidl_cb); +} + +Return Vibrator::perform_1_2(Effect effect, EffectStrength strength, perform_cb _hidl_cb) { + return performEffect(static_cast(effect), strength, _hidl_cb); +} + +Return Vibrator::performEffect(Effect effect, EffectStrength strength, perform_cb _hidl_cb) { Status status = Status::OK; uint32_t timeMS; - if (effect == Effect::CLICK) { + switch (effect) { + case Effect::CLICK: mSequencer << WAVEFORM_CLICK_EFFECT_SEQ << std::endl; timeMS = mClickDuration; - } else if (effect == Effect::DOUBLE_CLICK) { + break; + case Effect::DOUBLE_CLICK: mSequencer << WAVEFORM_DOUBLE_CLICK_EFFECT_SEQ << std::endl; timeMS = WAVEFORM_DOUBLE_CLICK_EFFECT_MS; - } else { - _hidl_cb(Status::UNSUPPORTED_OPERATION, 0); - return Void(); - } - - mScale << convertEffectStrength(strength) << std::endl; - on(timeMS, true /* forceOpenLoop */, true /* isWaveform */); - - _hidl_cb(status, timeMS); - return Void(); -} - -Return Vibrator::perform_1_1(Effect_1_1 effect, EffectStrength strength, - perform_cb _hidl_cb) { - Status status = Status::OK; - uint32_t timeMS; - - if (effect == Effect_1_1::TICK) { + break; + case Effect::TICK: mSequencer << WAVEFORM_TICK_EFFECT_SEQ << std::endl; timeMS = mTickDuration; - } else if (effect < Effect_1_1::TICK) { - return perform(static_cast(effect), strength, _hidl_cb); - } else { + break; + default: _hidl_cb(Status::UNSUPPORTED_OPERATION, 0); return Void(); } - mScale << convertEffectStrength(strength) << std::endl; on(timeMS, true /* forceOpenLoop */, true /* isWaveform */); - _hidl_cb(status, timeMS); return Void(); } + } // namespace implementation -} // namespace V1_1 +} // namespace V1_2 } // namespace vibrator } // namespace hardware } // namespace android diff --git a/vibrator/Vibrator.h b/vibrator/Vibrator.h index 82d4da20..2f0ed082 100644 --- a/vibrator/Vibrator.h +++ b/vibrator/Vibrator.h @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef ANDROID_HARDWARE_VIBRATOR_V1_1_VIBRATOR_H -#define ANDROID_HARDWARE_VIBRATOR_V1_1_VIBRATOR_H +#ifndef ANDROID_HARDWARE_VIBRATOR_V1_2_VIBRATOR_H +#define ANDROID_HARDWARE_VIBRATOR_V1_2_VIBRATOR_H -#include +#include #include #include @@ -24,7 +24,7 @@ namespace android { namespace hardware { namespace vibrator { -namespace V1_1 { +namespace V1_2 { namespace implementation { class Vibrator : public IVibrator { @@ -42,12 +42,15 @@ public: Return setAmplitude(uint8_t amplitude) override; using EffectStrength = ::android::hardware::vibrator::V1_0::EffectStrength; - using Effect = ::android::hardware::vibrator::V1_0::Effect; - Return perform(Effect effect, EffectStrength strength, perform_cb _hidl_cb) override; - Return perform_1_1(Effect_1_1 effect, EffectStrength strength, perform_cb _hidl_cb) override; + Return perform(V1_0::Effect effect, EffectStrength strength, perform_cb _hidl_cb) + override; + Return perform_1_1(V1_1::Effect_1_1 effect, EffectStrength strength, perform_cb _hidl_cb) + override; + Return perform_1_2(Effect effect, EffectStrength strength, perform_cb _hidl_cb) override; private: Return on(uint32_t timeoutMs, bool forceOpenLoop, bool isWaveform); + Return performEffect(Effect effect, EffectStrength strength, perform_cb _hidl_cb); std::ofstream mActivate; std::ofstream mDuration; std::ofstream mState; @@ -61,9 +64,9 @@ private: int32_t mTickDuration; }; } // namespace implementation -} // namespace V1_1 +} // namespace V1_2 } // namespace vibrator } // namespace hardware } // namespace android -#endif // ANDROID_HARDWARE_VIBRATOR_V1_1_VIBRATOR_H +#endif // ANDROID_HARDWARE_VIBRATOR_V1_2_VIBRATOR_H diff --git a/vibrator/android.hardware.vibrator@1.1-service.wahoo.rc b/vibrator/android.hardware.vibrator@1.1-service.wahoo.rc deleted file mode 100644 index be266bab..00000000 --- a/vibrator/android.hardware.vibrator@1.1-service.wahoo.rc +++ /dev/null @@ -1,4 +0,0 @@ -service vendor.vibrator-1-1 /vendor/bin/hw/android.hardware.vibrator@1.1-service.wahoo - class hal - user system - group system diff --git a/vibrator/android.hardware.vibrator@1.2-service.wahoo.rc b/vibrator/android.hardware.vibrator@1.2-service.wahoo.rc new file mode 100644 index 00000000..b5397861 --- /dev/null +++ b/vibrator/android.hardware.vibrator@1.2-service.wahoo.rc @@ -0,0 +1,4 @@ +service vendor.vibrator-1-2 /vendor/bin/hw/android.hardware.vibrator@1.2-service.wahoo + class hal + user system + group system diff --git a/vibrator/service.cpp b/vibrator/service.cpp index 25c49c55..ea05151d 100644 --- a/vibrator/service.cpp +++ b/vibrator/service.cpp @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#define LOG_TAG "android.hardware.vibrator@1.1-service.wahoo" +#define LOG_TAG "android.hardware.vibrator@1.2-service.wahoo" -#include +#include #include #include #include @@ -25,8 +25,8 @@ using android::hardware::configureRpcThreadpool; using android::hardware::joinRpcThreadpool; -using android::hardware::vibrator::V1_1::IVibrator; -using android::hardware::vibrator::V1_1::implementation::Vibrator; +using android::hardware::vibrator::V1_2::IVibrator; +using android::hardware::vibrator::V1_2::implementation::Vibrator; using namespace android; // Refer to Documentation/ABI/testing/sysfs-class-led-driver-drv2624