Loading services/vibratorservice/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ cc_library_shared { "VibratorCallbackScheduler.cpp", "VibratorHalController.cpp", "VibratorHalWrapper.cpp", "VibratorManagerHalWrapper.cpp", ], aidl: { Loading services/vibratorservice/VibratorHalController.cpp +4 −3 Original line number Diff line number Diff line Loading @@ -46,8 +46,6 @@ namespace vibrator { // ------------------------------------------------------------------------------------------------- static constexpr int MAX_RETRIES = 1; std::shared_ptr<HalWrapper> HalConnector::connect(std::shared_ptr<CallbackScheduler> scheduler) { static bool gHalExists = true; if (!gHalExists) { Loading Loading @@ -89,6 +87,8 @@ std::shared_ptr<HalWrapper> HalConnector::connect(std::shared_ptr<CallbackSchedu // ------------------------------------------------------------------------------------------------- static constexpr int MAX_RETRIES = 1; template <typename T> HalResult<T> HalController::processHalResult(HalResult<T> result, const char* functionName) { if (result.isFailed()) { Loading Loading @@ -126,11 +126,12 @@ HalResult<T> HalController::apply(HalController::hal_fn<T>& halFn, const char* f // ------------------------------------------------------------------------------------------------- void HalController::init() { bool HalController::init() { std::lock_guard<std::mutex> lock(mConnectedHalMutex); if (mConnectedHal == nullptr) { mConnectedHal = mHalConnector->connect(mCallbackScheduler); } return mConnectedHal != nullptr; } HalResult<void> HalController::ping() { Loading services/vibratorservice/VibratorManagerHalWrapper.cpp 0 → 100644 +68 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #define LOG_TAG "VibratorManagerHalWrapper" #include <utils/Log.h> #include <vibratorservice/VibratorManagerHalWrapper.h> namespace android { namespace vibrator { constexpr int32_t SINGLE_VIBRATOR_ID = 0; HalResult<void> LegacyManagerHalWrapper::ping() { return mController->ping(); } void LegacyManagerHalWrapper::tryReconnect() { mController->tryReconnect(); } HalResult<std::vector<int32_t>> LegacyManagerHalWrapper::getVibratorIds() { if (mController->init()) { return HalResult<std::vector<int32_t>>::ok(std::vector<int32_t>(1, SINGLE_VIBRATOR_ID)); } // Controller.init did not connect to any vibrator HAL service, so the device has no vibrator. return HalResult<std::vector<int32_t>>::ok(std::vector<int32_t>()); } HalResult<std::shared_ptr<HalController>> LegacyManagerHalWrapper::getVibrator(int32_t id) { if (id == SINGLE_VIBRATOR_ID && mController->init()) { return HalResult<std::shared_ptr<HalController>>::ok(mController); } // Controller.init did not connect to any vibrator HAL service, so the device has no vibrator. return HalResult<std::shared_ptr<HalController>>::failed("No vibrator with id = " + std::to_string(id)); } HalResult<void> LegacyManagerHalWrapper::prepareSynced(const std::vector<int32_t>&) { return HalResult<void>::unsupported(); } HalResult<void> LegacyManagerHalWrapper::triggerSynced(const std::function<void()>&) { return HalResult<void>::unsupported(); } HalResult<void> LegacyManagerHalWrapper::cancelSynced() { return HalResult<void>::unsupported(); } }; // namespace vibrator }; // namespace android services/vibratorservice/include/vibratorservice/VibratorHalController.h +13 −5 Original line number Diff line number Diff line Loading @@ -51,11 +51,19 @@ public: mConnectedHal(nullptr) {} virtual ~HalController() = default; void init(); /* Connects to the newest HAL version available, possibly waiting for the registered service to * become available. This will automatically be called at the first API usage if it was not * manually called beforehand. Calling this manually during the setup phase can avoid slowing * the first API call later on. Returns true if any HAL version is available, false otherwise. */ virtual bool init(); HalResult<void> ping() final override; void tryReconnect() final override; /* reloads HAL service instance without waiting. This relies on the HAL version found by init() * to rapidly reconnect to the specific HAL service, or defers to init() if it was never called. */ virtual void tryReconnect() override; virtual HalResult<void> ping() override; HalResult<void> on(std::chrono::milliseconds timeout, const std::function<void()>& completionCallback) final override; HalResult<void> off() final override; Loading services/vibratorservice/include/vibratorservice/VibratorHalWrapper.h +4 −1 Original line number Diff line number Diff line Loading @@ -140,9 +140,12 @@ public: : mCallbackScheduler(std::move(scheduler)) {} virtual ~HalWrapper() = default; virtual HalResult<void> ping() = 0; /* reloads wrapped HAL service instance without waiting. This can be used to reconnect when the * service restarts, to rapidly retry after a failure. */ virtual void tryReconnect() = 0; virtual HalResult<void> ping() = 0; virtual HalResult<void> on(std::chrono::milliseconds timeout, const std::function<void()>& completionCallback) = 0; virtual HalResult<void> off() = 0; Loading Loading
services/vibratorservice/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ cc_library_shared { "VibratorCallbackScheduler.cpp", "VibratorHalController.cpp", "VibratorHalWrapper.cpp", "VibratorManagerHalWrapper.cpp", ], aidl: { Loading
services/vibratorservice/VibratorHalController.cpp +4 −3 Original line number Diff line number Diff line Loading @@ -46,8 +46,6 @@ namespace vibrator { // ------------------------------------------------------------------------------------------------- static constexpr int MAX_RETRIES = 1; std::shared_ptr<HalWrapper> HalConnector::connect(std::shared_ptr<CallbackScheduler> scheduler) { static bool gHalExists = true; if (!gHalExists) { Loading Loading @@ -89,6 +87,8 @@ std::shared_ptr<HalWrapper> HalConnector::connect(std::shared_ptr<CallbackSchedu // ------------------------------------------------------------------------------------------------- static constexpr int MAX_RETRIES = 1; template <typename T> HalResult<T> HalController::processHalResult(HalResult<T> result, const char* functionName) { if (result.isFailed()) { Loading Loading @@ -126,11 +126,12 @@ HalResult<T> HalController::apply(HalController::hal_fn<T>& halFn, const char* f // ------------------------------------------------------------------------------------------------- void HalController::init() { bool HalController::init() { std::lock_guard<std::mutex> lock(mConnectedHalMutex); if (mConnectedHal == nullptr) { mConnectedHal = mHalConnector->connect(mCallbackScheduler); } return mConnectedHal != nullptr; } HalResult<void> HalController::ping() { Loading
services/vibratorservice/VibratorManagerHalWrapper.cpp 0 → 100644 +68 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #define LOG_TAG "VibratorManagerHalWrapper" #include <utils/Log.h> #include <vibratorservice/VibratorManagerHalWrapper.h> namespace android { namespace vibrator { constexpr int32_t SINGLE_VIBRATOR_ID = 0; HalResult<void> LegacyManagerHalWrapper::ping() { return mController->ping(); } void LegacyManagerHalWrapper::tryReconnect() { mController->tryReconnect(); } HalResult<std::vector<int32_t>> LegacyManagerHalWrapper::getVibratorIds() { if (mController->init()) { return HalResult<std::vector<int32_t>>::ok(std::vector<int32_t>(1, SINGLE_VIBRATOR_ID)); } // Controller.init did not connect to any vibrator HAL service, so the device has no vibrator. return HalResult<std::vector<int32_t>>::ok(std::vector<int32_t>()); } HalResult<std::shared_ptr<HalController>> LegacyManagerHalWrapper::getVibrator(int32_t id) { if (id == SINGLE_VIBRATOR_ID && mController->init()) { return HalResult<std::shared_ptr<HalController>>::ok(mController); } // Controller.init did not connect to any vibrator HAL service, so the device has no vibrator. return HalResult<std::shared_ptr<HalController>>::failed("No vibrator with id = " + std::to_string(id)); } HalResult<void> LegacyManagerHalWrapper::prepareSynced(const std::vector<int32_t>&) { return HalResult<void>::unsupported(); } HalResult<void> LegacyManagerHalWrapper::triggerSynced(const std::function<void()>&) { return HalResult<void>::unsupported(); } HalResult<void> LegacyManagerHalWrapper::cancelSynced() { return HalResult<void>::unsupported(); } }; // namespace vibrator }; // namespace android
services/vibratorservice/include/vibratorservice/VibratorHalController.h +13 −5 Original line number Diff line number Diff line Loading @@ -51,11 +51,19 @@ public: mConnectedHal(nullptr) {} virtual ~HalController() = default; void init(); /* Connects to the newest HAL version available, possibly waiting for the registered service to * become available. This will automatically be called at the first API usage if it was not * manually called beforehand. Calling this manually during the setup phase can avoid slowing * the first API call later on. Returns true if any HAL version is available, false otherwise. */ virtual bool init(); HalResult<void> ping() final override; void tryReconnect() final override; /* reloads HAL service instance without waiting. This relies on the HAL version found by init() * to rapidly reconnect to the specific HAL service, or defers to init() if it was never called. */ virtual void tryReconnect() override; virtual HalResult<void> ping() override; HalResult<void> on(std::chrono::milliseconds timeout, const std::function<void()>& completionCallback) final override; HalResult<void> off() final override; Loading
services/vibratorservice/include/vibratorservice/VibratorHalWrapper.h +4 −1 Original line number Diff line number Diff line Loading @@ -140,9 +140,12 @@ public: : mCallbackScheduler(std::move(scheduler)) {} virtual ~HalWrapper() = default; virtual HalResult<void> ping() = 0; /* reloads wrapped HAL service instance without waiting. This can be used to reconnect when the * service restarts, to rapidly retry after a failure. */ virtual void tryReconnect() = 0; virtual HalResult<void> ping() = 0; virtual HalResult<void> on(std::chrono::milliseconds timeout, const std::function<void()>& completionCallback) = 0; virtual HalResult<void> off() = 0; Loading