diff --git a/universal7885-common/aidl/light/Lights.cpp b/universal7885-common/aidl/light/Lights.cpp index 749030e..b1e8068 100644 --- a/universal7885-common/aidl/light/Lights.cpp +++ b/universal7885-common/aidl/light/Lights.cpp @@ -41,10 +41,12 @@ Lights::Lights() { mLights.emplace(LightType::BACKLIGHT, std::bind(&Lights::handleBacklight, this, std::placeholders::_1)); #ifdef BUTTON_BRIGHTNESS_NODE - mLights.emplace(LightType::BUTTONS, std::bind(&Lights::handleButtons, this, std::placeholders::_1)); + mLights.emplace(LightType::BUTTONS, + std::bind(&Lights::handleButtons, this, std::placeholders::_1)); #endif /* BUTTON_BRIGHTNESS_NODE */ #ifdef LED_BLINK_NODE - mLights.emplace(LightType::BATTERY, std::bind(&Lights::handleBattery, this, std::placeholders::_1)); + mLights.emplace(LightType::BATTERY, + std::bind(&Lights::handleBattery, this, std::placeholders::_1)); mLights.emplace(LightType::NOTIFICATIONS, std::bind(&Lights::handleNotifications, this, std::placeholders::_1)); mLights.emplace(LightType::ATTENTION, @@ -147,7 +149,7 @@ void Lights::setNotificationLED() { state.color = calibrateColor(state.color & COLOR_MASK, adjusted_brightness); set(LED_BLINK_NODE, ::android::base::StringPrintf("0x%08x %d %d", state.color, state.flashOnMs, - state.flashOffMs)); + state.flashOffMs)); #ifdef LED_BLN_NODE if (bln) { @@ -166,9 +168,10 @@ uint32_t Lights::calibrateColor(uint32_t color, int32_t brightness) { } #endif /* LED_BLINK_NODE */ -#define AutoHwLight(light) {.id = (int32_t)light, .type = light, .ordinal = 0} +#define AutoHwLight(light) \ + { .id = (int32_t)light, .type = light, .ordinal = 0 } -ndk::ScopedAStatus Lights::getLights(std::vector *_aidl_return) { +ndk::ScopedAStatus Lights::getLights(std::vector* _aidl_return) { for (auto const& light : mLights) { _aidl_return->push_back(AutoHwLight(light.first)); } @@ -179,11 +182,12 @@ ndk::ScopedAStatus Lights::getLights(std::vector *_aidl_return) { uint32_t Lights::rgbToBrightness(const HwLightState& state) { uint32_t color = state.color & COLOR_MASK; - return ((77 * ((color >> 16) & 0xff)) + (150 * ((color >> 8) & 0xff)) + (29 * (color & 0xff))) >> + return ((77 * ((color >> 16) & 0xff)) + (150 * ((color >> 8) & 0xff)) + + (29 * (color & 0xff))) >> 8; } -} // namespace light -} // namespace hardware -} // namespace android -} // namespace aidl +} // namespace light +} // namespace hardware +} // namespace android +} // namespace aidl diff --git a/universal7885-common/aidl/light/Lights.h b/universal7885-common/aidl/light/Lights.h index 253167b..824249f 100644 --- a/universal7885-common/aidl/light/Lights.h +++ b/universal7885-common/aidl/light/Lights.h @@ -10,8 +10,8 @@ #include #include "samsung_lights.h" -using ::aidl::android::hardware::light::HwLightState; using ::aidl::android::hardware::light::HwLight; +using ::aidl::android::hardware::light::HwLightState; namespace aidl { namespace android { @@ -19,13 +19,13 @@ namespace hardware { namespace light { class Lights : public BnLights { -public: + public: Lights(); ndk::ScopedAStatus setLightState(int32_t id, const HwLightState& state) override; - ndk::ScopedAStatus getLights(std::vector *_aidl_return) override; + ndk::ScopedAStatus getLights(std::vector* _aidl_return) override; -private: + private: void handleBacklight(const HwLightState& state); #ifdef BUTTON_BRIGHTNESS_NODE void handleButtons(const HwLightState& state); @@ -48,7 +48,7 @@ private: std::unordered_map> mLights; }; -} // namespace light -} // namespace hardware -} // namespace android -} // namespace aidl +} // namespace light +} // namespace hardware +} // namespace android +} // namespace aidl diff --git a/universal7885-common/aidl/light/service.cpp b/universal7885-common/aidl/light/service.cpp index bd3b7a7..c859b1c 100644 --- a/universal7885-common/aidl/light/service.cpp +++ b/universal7885-common/aidl/light/service.cpp @@ -8,9 +8,9 @@ #include "Lights.h" +#include #include #include -#include using ::aidl::android::hardware::light::Lights; @@ -23,5 +23,5 @@ int main() { CHECK(status == STATUS_OK); ABinderProcess_joinThreadPool(); - return EXIT_FAILURE; // should not reach + return EXIT_FAILURE; // should not reach } diff --git a/universal7885-common/aidl/power-libperfmgr/InteractionHandler.cpp b/universal7885-common/aidl/power-libperfmgr/InteractionHandler.cpp index 0c28365..cf70071 100644 --- a/universal7885-common/aidl/power-libperfmgr/InteractionHandler.cpp +++ b/universal7885-common/aidl/power-libperfmgr/InteractionHandler.cpp @@ -36,7 +36,7 @@ static const std::vector fb_idle_patch = {"/sys/class/drm/card0/device/idle_state", "/sys/class/graphics/fb0/idle_state"}; -InteractionHandler::InteractionHandler(std::shared_ptr const &hint_manager) +InteractionHandler::InteractionHandler(std::shared_ptr const& hint_manager) : mState(INTERACTION_STATE_UNINITIALIZED), mWaitMs(100), mMinDurationMs(1400), @@ -50,10 +50,9 @@ InteractionHandler::~InteractionHandler() { static int fb_idle_open(void) { int fd; - for (auto &path : fb_idle_patch) { + for (auto& path : fb_idle_patch) { fd = open(path.c_str(), O_RDONLY); - if (fd >= 0) - return fd; + if (fd >= 0) return fd; } ALOGE("Unable to open fb idle state path (%d)", errno); return -1; @@ -62,8 +61,7 @@ static int fb_idle_open(void) { bool InteractionHandler::Init() { std::lock_guard lk(mLock); - if (mState != INTERACTION_STATE_UNINITIALIZED) - return true; + if (mState != INTERACTION_STATE_UNINITIALIZED) return true; mIdleFd = fb_idle_open(); @@ -84,8 +82,7 @@ bool InteractionHandler::Init() { void InteractionHandler::Exit() { std::unique_lock lk(mLock); - if (mState == INTERACTION_STATE_UNINITIALIZED) - return; + if (mState == INTERACTION_STATE_UNINITIALIZED) return; AbortWaitLocked(); mState = INTERACTION_STATE_UNINITIALIZED; @@ -186,8 +183,7 @@ void InteractionHandler::Release() { void InteractionHandler::AbortWaitLocked() { uint64_t val = 1; ssize_t ret = write(mEventFd, &val, sizeof(val)); - if (ret != sizeof(val)) - ALOGW("Unable to write to event fd (%zd)", ret); + if (ret != sizeof(val)) ALOGW("Unable to write to event fd (%zd)", ret); } void InteractionHandler::WaitForIdle(int32_t wait_ms, int32_t timeout_ms) { @@ -253,8 +249,7 @@ void InteractionHandler::Routine() { while (true) { lk.lock(); mCond.wait(lk, [&] { return mState != INTERACTION_STATE_IDLE; }); - if (mState == INTERACTION_STATE_UNINITIALIZED) - return; + if (mState == INTERACTION_STATE_UNINITIALIZED) return; mState = INTERACTION_STATE_WAITING; lk.unlock(); diff --git a/universal7885-common/aidl/power-libperfmgr/InteractionHandler.h b/universal7885-common/aidl/power-libperfmgr/InteractionHandler.h index ba767f1..16f1ecc 100644 --- a/universal7885-common/aidl/power-libperfmgr/InteractionHandler.h +++ b/universal7885-common/aidl/power-libperfmgr/InteractionHandler.h @@ -36,7 +36,7 @@ enum interaction_state { class InteractionHandler { public: - InteractionHandler(std::shared_ptr const &hint_manager); + InteractionHandler(std::shared_ptr const& hint_manager); ~InteractionHandler(); bool Init(); void Exit(); diff --git a/universal7885-common/aidl/power-libperfmgr/Power.cpp b/universal7885-common/aidl/power-libperfmgr/Power.cpp index b7a51d9..cf40990 100644 --- a/universal7885-common/aidl/power-libperfmgr/Power.cpp +++ b/universal7885-common/aidl/power-libperfmgr/Power.cpp @@ -169,10 +169,10 @@ ndk::ScopedAStatus Power::setMode(Mode type, bool enabled) { return ndk::ScopedAStatus::ok(); } -ndk::ScopedAStatus Power::isModeSupported(Mode type, bool *_aidl_return) { +ndk::ScopedAStatus Power::isModeSupported(Mode type, bool* _aidl_return) { bool supported = mHintManager->IsHintSupported(toString(type)); switch (type) { - case Mode::LOW_POWER: // LOW_POWER handled insides PowerHAL specifically + case Mode::LOW_POWER: // LOW_POWER handled insides PowerHAL specifically supported = true; break; case Mode::DOUBLE_TAP_TO_WAKE: @@ -227,18 +227,18 @@ ndk::ScopedAStatus Power::setBoost(Boost type, int32_t durationMs) { return ndk::ScopedAStatus::ok(); } -ndk::ScopedAStatus Power::isBoostSupported(Boost type, bool *_aidl_return) { +ndk::ScopedAStatus Power::isBoostSupported(Boost type, bool* _aidl_return) { bool supported = mHintManager->IsHintSupported(toString(type)); LOG(INFO) << "Power boost " << toString(type) << " isBoostSupported: " << supported; *_aidl_return = supported; return ndk::ScopedAStatus::ok(); } -constexpr const char *boolToString(bool b) { +constexpr const char* boolToString(bool b) { return b ? "true" : "false"; } -binder_status_t Power::dump(int fd, const char **, uint32_t) { +binder_status_t Power::dump(int fd, const char**, uint32_t) { std::string buf(::android::base::StringPrintf( "HintManager Running: %s\n" "VRMode: %s\n" diff --git a/universal7885-common/aidl/power-libperfmgr/Power.h b/universal7885-common/aidl/power-libperfmgr/Power.h index 04e16d6..a7d0cdb 100644 --- a/universal7885-common/aidl/power-libperfmgr/Power.h +++ b/universal7885-common/aidl/power-libperfmgr/Power.h @@ -41,10 +41,10 @@ class Power : public ::aidl::android::hardware::power::BnPower { public: Power(std::shared_ptr hm); ndk::ScopedAStatus setMode(Mode type, bool enabled) override; - ndk::ScopedAStatus isModeSupported(Mode type, bool *_aidl_return) override; + ndk::ScopedAStatus isModeSupported(Mode type, bool* _aidl_return) override; ndk::ScopedAStatus setBoost(Boost type, int32_t durationMs) override; - ndk::ScopedAStatus isBoostSupported(Boost type, bool *_aidl_return) override; - binder_status_t dump(int fd, const char **args, uint32_t numArgs) override; + ndk::ScopedAStatus isBoostSupported(Boost type, bool* _aidl_return) override; + binder_status_t dump(int fd, const char** args, uint32_t numArgs) override; private: std::shared_ptr mHintManager; diff --git a/universal7885-common/aidl/power-libperfmgr/PowerExt.cpp b/universal7885-common/aidl/power-libperfmgr/PowerExt.cpp index 6f854b0..96ab0ee 100644 --- a/universal7885-common/aidl/power-libperfmgr/PowerExt.cpp +++ b/universal7885-common/aidl/power-libperfmgr/PowerExt.cpp @@ -37,7 +37,7 @@ namespace power { namespace impl { namespace pixel { -ndk::ScopedAStatus PowerExt::setMode(const std::string &mode, bool enabled) { +ndk::ScopedAStatus PowerExt::setMode(const std::string& mode, bool enabled) { LOG(DEBUG) << "PowerExt setMode: " << mode << " to: " << enabled; ATRACE_INT(mode.c_str(), enabled); @@ -50,14 +50,14 @@ ndk::ScopedAStatus PowerExt::setMode(const std::string &mode, bool enabled) { return ndk::ScopedAStatus::ok(); } -ndk::ScopedAStatus PowerExt::isModeSupported(const std::string &mode, bool *_aidl_return) { +ndk::ScopedAStatus PowerExt::isModeSupported(const std::string& mode, bool* _aidl_return) { bool supported = mHintManager->IsHintSupported(mode); LOG(INFO) << "PowerExt mode " << mode << " isModeSupported: " << supported; *_aidl_return = supported; return ndk::ScopedAStatus::ok(); } -ndk::ScopedAStatus PowerExt::setBoost(const std::string &boost, int32_t durationMs) { +ndk::ScopedAStatus PowerExt::setBoost(const std::string& boost, int32_t durationMs) { LOG(DEBUG) << "PowerExt setBoost: " << boost << " duration: " << durationMs; ATRACE_INT(boost.c_str(), durationMs); @@ -72,7 +72,7 @@ ndk::ScopedAStatus PowerExt::setBoost(const std::string &boost, int32_t duration return ndk::ScopedAStatus::ok(); } -ndk::ScopedAStatus PowerExt::isBoostSupported(const std::string &boost, bool *_aidl_return) { +ndk::ScopedAStatus PowerExt::isBoostSupported(const std::string& boost, bool* _aidl_return) { bool supported = mHintManager->IsHintSupported(boost); LOG(INFO) << "PowerExt boost " << boost << " isBoostSupported: " << supported; *_aidl_return = supported; diff --git a/universal7885-common/aidl/power-libperfmgr/PowerExt.h b/universal7885-common/aidl/power-libperfmgr/PowerExt.h index c24d650..0c70de6 100644 --- a/universal7885-common/aidl/power-libperfmgr/PowerExt.h +++ b/universal7885-common/aidl/power-libperfmgr/PowerExt.h @@ -34,12 +34,11 @@ using ::android::perfmgr::HintManager; class PowerExt : public ::aidl::google::hardware::power::extension::pixel::BnPowerExt { public: - PowerExt(std::shared_ptr hm) - : mHintManager(hm) {} - ndk::ScopedAStatus setMode(const std::string &mode, bool enabled) override; - ndk::ScopedAStatus isModeSupported(const std::string &mode, bool *_aidl_return) override; - ndk::ScopedAStatus setBoost(const std::string &boost, int32_t durationMs) override; - ndk::ScopedAStatus isBoostSupported(const std::string &boost, bool *_aidl_return) override; + PowerExt(std::shared_ptr hm) : mHintManager(hm) {} + ndk::ScopedAStatus setMode(const std::string& mode, bool enabled) override; + ndk::ScopedAStatus isModeSupported(const std::string& mode, bool* _aidl_return) override; + ndk::ScopedAStatus setBoost(const std::string& boost, int32_t durationMs) override; + ndk::ScopedAStatus isBoostSupported(const std::string& boost, bool* _aidl_return) override; private: std::shared_ptr mHintManager; diff --git a/universal7885-common/aidl/vibrator/Vibrator.cpp b/universal7885-common/aidl/vibrator/Vibrator.cpp index f21eee3..cf93d70 100644 --- a/universal7885-common/aidl/vibrator/Vibrator.cpp +++ b/universal7885-common/aidl/vibrator/Vibrator.cpp @@ -53,7 +53,8 @@ Vibrator::Vibrator() { ndk::ScopedAStatus Vibrator::getCapabilities(int32_t* _aidl_return) { *_aidl_return = IVibrator::CAP_ON_CALLBACK | IVibrator::CAP_PERFORM_CALLBACK | IVibrator::CAP_EXTERNAL_CONTROL /*| IVibrator::CAP_COMPOSE_EFFECTS | - IVibrator::CAP_ALWAYS_ON_CONTROL*/; + IVibrator::CAP_ALWAYS_ON_CONTROL*/ + ; if (mHasTimedOutIntensity) { *_aidl_return = *_aidl_return | IVibrator::CAP_AMPLITUDE_CONTROL | @@ -67,7 +68,8 @@ ndk::ScopedAStatus Vibrator::off() { return activate(0); } -ndk::ScopedAStatus Vibrator::on(int32_t timeoutMs, const std::shared_ptr& callback) { +ndk::ScopedAStatus Vibrator::on(int32_t timeoutMs, + const std::shared_ptr& callback) { ndk::ScopedAStatus status = activate(timeoutMs); if (callback != nullptr) { @@ -84,7 +86,9 @@ ndk::ScopedAStatus Vibrator::on(int32_t timeoutMs, const std::shared_ptr& callback, int32_t* _aidl_return) { +ndk::ScopedAStatus Vibrator::perform(Effect effect, EffectStrength strength, + const std::shared_ptr& callback, + int32_t* _aidl_return) { ndk::ScopedAStatus status; uint8_t amplitude; uint32_t ms; @@ -115,14 +119,13 @@ ndk::ScopedAStatus Vibrator::perform(Effect effect, EffectStrength strength, con } ndk::ScopedAStatus Vibrator::getSupportedEffects(std::vector* _aidl_return) { - *_aidl_return = {Effect::CLICK, Effect::DOUBLE_CLICK, Effect::HEAVY_CLICK, - Effect::TICK, Effect::TEXTURE_TICK, Effect::THUD, Effect::POP, - Effect::RINGTONE_1, Effect::RINGTONE_2, Effect::RINGTONE_3, - Effect::RINGTONE_4, Effect::RINGTONE_5, Effect::RINGTONE_6, - Effect::RINGTONE_7, Effect::RINGTONE_7, Effect::RINGTONE_8, - Effect::RINGTONE_9, Effect::RINGTONE_10, Effect::RINGTONE_11, - Effect::RINGTONE_12, Effect::RINGTONE_13, Effect::RINGTONE_14, - Effect::RINGTONE_15}; + *_aidl_return = { + Effect::CLICK, Effect::DOUBLE_CLICK, Effect::HEAVY_CLICK, Effect::TICK, + Effect::TEXTURE_TICK, Effect::THUD, Effect::POP, Effect::RINGTONE_1, + Effect::RINGTONE_2, Effect::RINGTONE_3, Effect::RINGTONE_4, Effect::RINGTONE_5, + Effect::RINGTONE_6, Effect::RINGTONE_7, Effect::RINGTONE_7, Effect::RINGTONE_8, + Effect::RINGTONE_9, Effect::RINGTONE_10, Effect::RINGTONE_11, Effect::RINGTONE_12, + Effect::RINGTONE_13, Effect::RINGTONE_14, Effect::RINGTONE_15}; return ndk::ScopedAStatus::ok(); } @@ -168,15 +171,18 @@ ndk::ScopedAStatus Vibrator::getCompositionSizeMax(int32_t* /*_aidl_return*/) { return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); } -ndk::ScopedAStatus Vibrator::getSupportedPrimitives(std::vector* /*_aidl_return*/) { +ndk::ScopedAStatus Vibrator::getSupportedPrimitives( + std::vector* /*_aidl_return*/) { return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); } -ndk::ScopedAStatus Vibrator::getPrimitiveDuration(CompositePrimitive /*primitive*/, int32_t* /*_aidl_return*/) { +ndk::ScopedAStatus Vibrator::getPrimitiveDuration(CompositePrimitive /*primitive*/, + int32_t* /*_aidl_return*/) { return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); } -ndk::ScopedAStatus Vibrator::compose(const std::vector& /*composite*/, const std::shared_ptr& /*callback*/) { +ndk::ScopedAStatus Vibrator::compose(const std::vector& /*composite*/, + const std::shared_ptr& /*callback*/) { return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); } @@ -184,7 +190,8 @@ ndk::ScopedAStatus Vibrator::getSupportedAlwaysOnEffects(std::vector* /* return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); } -ndk::ScopedAStatus Vibrator::alwaysOnEnable(int32_t /*id*/, Effect /*effect*/, EffectStrength /*strength*/) { +ndk::ScopedAStatus Vibrator::alwaysOnEnable(int32_t /*id*/, Effect /*effect*/, + EffectStrength /*strength*/) { return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); } @@ -224,7 +231,8 @@ ndk::ScopedAStatus Vibrator::getSupportedBraking(std::vector* /*_aidl_r return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); } -ndk::ScopedAStatus Vibrator::composePwle(const std::vector& /*composite*/, const std::shared_ptr& /*callback*/) { +ndk::ScopedAStatus Vibrator::composePwle(const std::vector& /*composite*/, + const std::shared_ptr& /*callback*/) { return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); } @@ -290,7 +298,7 @@ uint32_t Vibrator::effectToMs(Effect effect, ndk::ScopedAStatus* status) { return 0; } -} // namespace vibrator -} // namespace hardware -} // namespace android -} // namespace aidl +} // namespace vibrator +} // namespace hardware +} // namespace android +} // namespace aidl diff --git a/universal7885-common/aidl/vibrator/Vibrator.h b/universal7885-common/aidl/vibrator/Vibrator.h index 6770527..d7950bb 100644 --- a/universal7885-common/aidl/vibrator/Vibrator.h +++ b/universal7885-common/aidl/vibrator/Vibrator.h @@ -15,12 +15,12 @@ #define VIBRATOR_TIMEOUT_PATH "/sys/class/timed_output/vibrator/enable" #define VIBRATOR_INTENSITY_PATH "/sys/class/timed_output/vibrator/intensity" -using ::aidl::android::hardware::vibrator::IVibratorCallback; using ::aidl::android::hardware::vibrator::Braking; -using ::aidl::android::hardware::vibrator::Effect; -using ::aidl::android::hardware::vibrator::EffectStrength; using ::aidl::android::hardware::vibrator::CompositeEffect; using ::aidl::android::hardware::vibrator::CompositePrimitive; +using ::aidl::android::hardware::vibrator::Effect; +using ::aidl::android::hardware::vibrator::EffectStrength; +using ::aidl::android::hardware::vibrator::IVibratorCallback; using ::aidl::android::hardware::vibrator::PrimitivePwle; namespace aidl { @@ -29,20 +29,26 @@ namespace hardware { namespace vibrator { class Vibrator : public BnVibrator { -public: + public: Vibrator(); ndk::ScopedAStatus getCapabilities(int32_t* _aidl_return) override; ndk::ScopedAStatus off() override; - ndk::ScopedAStatus on(int32_t timeoutMs, const std::shared_ptr& callback) override; - ndk::ScopedAStatus perform(Effect effect, EffectStrength strength, const std::shared_ptr& callback, int32_t* _aidl_return) override; + ndk::ScopedAStatus on(int32_t timeoutMs, + const std::shared_ptr& callback) override; + ndk::ScopedAStatus perform(Effect effect, EffectStrength strength, + const std::shared_ptr& callback, + int32_t* _aidl_return) override; ndk::ScopedAStatus getSupportedEffects(std::vector* _aidl_return) override; ndk::ScopedAStatus setAmplitude(float amplitude) override; ndk::ScopedAStatus setExternalControl(bool enabled) override; ndk::ScopedAStatus getCompositionDelayMax(int32_t* _aidl_return) override; ndk::ScopedAStatus getCompositionSizeMax(int32_t* _aidl_return) override; - ndk::ScopedAStatus getSupportedPrimitives(std::vector* _aidl_return) override; - ndk::ScopedAStatus getPrimitiveDuration(CompositePrimitive primitive, int32_t* _aidl_return) override; - ndk::ScopedAStatus compose(const std::vector& composite, const std::shared_ptr& callback) override; + ndk::ScopedAStatus getSupportedPrimitives( + std::vector* _aidl_return) override; + ndk::ScopedAStatus getPrimitiveDuration(CompositePrimitive primitive, + int32_t* _aidl_return) override; + ndk::ScopedAStatus compose(const std::vector& composite, + const std::shared_ptr& callback) override; ndk::ScopedAStatus getSupportedAlwaysOnEffects(std::vector* _aidl_return) override; ndk::ScopedAStatus alwaysOnEnable(int32_t id, Effect effect, EffectStrength strength) override; ndk::ScopedAStatus alwaysOnDisable(int32_t id) override; @@ -54,9 +60,10 @@ public: ndk::ScopedAStatus getPwlePrimitiveDurationMax(int32_t* _aidl_return) override; ndk::ScopedAStatus getPwleCompositionSizeMax(int32_t* _aidl_return) override; ndk::ScopedAStatus getSupportedBraking(std::vector* _aidl_return) override; - ndk::ScopedAStatus composePwle(const std::vector& composite, const std::shared_ptr& callback) override; + ndk::ScopedAStatus composePwle(const std::vector& composite, + const std::shared_ptr& callback) override; -private: + private: ndk::ScopedAStatus activate(uint32_t ms); static uint32_t effectToMs(Effect effect, ndk::ScopedAStatus* status); static uint8_t strengthToAmplitude(EffectStrength strength, ndk::ScopedAStatus* status); @@ -69,7 +76,7 @@ private: bool mHasTimedOutIntensity; }; -} // namespace vibrator -} // namespace hardware -} // namespace android -} // namespace aidl +} // namespace vibrator +} // namespace hardware +} // namespace android +} // namespace aidl diff --git a/universal7885-common/aidl/vibrator/service.cpp b/universal7885-common/aidl/vibrator/service.cpp index db782c8..cff4daf 100644 --- a/universal7885-common/aidl/vibrator/service.cpp +++ b/universal7885-common/aidl/vibrator/service.cpp @@ -6,9 +6,9 @@ #include "Vibrator.h" +#include #include #include -#include using ::aidl::android::hardware::vibrator::Vibrator; @@ -17,9 +17,10 @@ int main() { std::shared_ptr vibrator = ndk::SharedRefBase::make(); const std::string instance = std::string() + Vibrator::descriptor + "/default"; - binder_status_t status = AServiceManager_addService(vibrator->asBinder().get(), instance.c_str()); + binder_status_t status = + AServiceManager_addService(vibrator->asBinder().get(), instance.c_str()); CHECK(status == STATUS_OK); ABinderProcess_joinThreadPool(); - return EXIT_FAILURE; // should not reach + return EXIT_FAILURE; // should not reach } diff --git a/universal7885-common/apps/SamsungParts/jni/BatteryBridge.cpp b/universal7885-common/apps/SamsungParts/jni/BatteryBridge.cpp index 31f7bec..26d3adb 100644 --- a/universal7885-common/apps/SamsungParts/jni/BatteryBridge.cpp +++ b/universal7885-common/apps/SamsungParts/jni/BatteryBridge.cpp @@ -1,98 +1,95 @@ -#include -#include -#include #include #include +#include +#include +#include #include "jni.h" -using vendor::eureka::hardware::battery::V1_0::IBattery; -using vendor::eureka::hardware::battery::V1_0::SysfsType; -using vendor::eureka::hardware::battery::V1_0::Number; using android::sp; - -extern "C" JNIEXPORT void -JNICALL -Java_com_eurekateam_samsungextras_interfaces_Battery_setChargeSysfs -(JNIEnv *env , __unused jclass obj, jint enable) { - android::sp service = IBattery::getService(); - if (enable == 1){ - service->setBatteryWritable(SysfsType::CHARGE, Number::ENABLE); - }else{ - service->setBatteryWritable(SysfsType::CHARGE, Number::DISABLE); - } +using vendor::eureka::hardware::battery::V1_0::IBattery; +using vendor::eureka::hardware::battery::V1_0::Number; +using vendor::eureka::hardware::battery::V1_0::SysfsType; + +extern "C" JNIEXPORT void JNICALL +Java_com_eurekateam_samsungextras_interfaces_Battery_setChargeSysfs(JNIEnv* env, + __unused jclass obj, + jint enable) { + android::sp service = IBattery::getService(); + if (enable == 1) { + service->setBatteryWritable(SysfsType::CHARGE, Number::ENABLE); + } else { + service->setBatteryWritable(SysfsType::CHARGE, Number::DISABLE); + } } -extern "C" JNIEXPORT jint -JNICALL -Java_com_eurekateam_samsungextras_interfaces_Battery_getChargeSysfs -(JNIEnv *env , __unused jclass obj) { - android::sp service = IBattery::getService(); - int ret = service->getBatteryStats(SysfsType::CHARGE); - return ret; +extern "C" JNIEXPORT jint JNICALL +Java_com_eurekateam_samsungextras_interfaces_Battery_getChargeSysfs(JNIEnv* env, + __unused jclass obj) { + android::sp service = IBattery::getService(); + int ret = service->getBatteryStats(SysfsType::CHARGE); + return ret; } -extern "C" -JNIEXPORT void JNICALL -Java_com_eurekateam_samsungextras_interfaces_Battery_setFastCharge(JNIEnv *env, __unused jobject obj, +extern "C" JNIEXPORT void JNICALL +Java_com_eurekateam_samsungextras_interfaces_Battery_setFastCharge(JNIEnv* env, + __unused jobject obj, jint enable) { - android::sp service = IBattery::getService(); - if (enable == 1){ - service->setBatteryWritable(SysfsType::FASTCHARGE, Number::ENABLE); - }else{ - service->setBatteryWritable(SysfsType::FASTCHARGE, Number::DISABLE); - } + android::sp service = IBattery::getService(); + if (enable == 1) { + service->setBatteryWritable(SysfsType::FASTCHARGE, Number::ENABLE); + } else { + service->setBatteryWritable(SysfsType::FASTCHARGE, Number::DISABLE); + } } -extern "C" -JNIEXPORT jint JNICALL -Java_com_eurekateam_samsungextras_interfaces_Battery_getFastChargeSysfs(JNIEnv *env, __unused -jclass obj) { - android::sp service = IBattery::getService(); - int ret = service->getBatteryStats(SysfsType::FASTCHARGE); - return ret; +extern "C" JNIEXPORT jint JNICALL +Java_com_eurekateam_samsungextras_interfaces_Battery_getFastChargeSysfs(JNIEnv* env, + __unused jclass obj) { + android::sp service = IBattery::getService(); + int ret = service->getBatteryStats(SysfsType::FASTCHARGE); + return ret; } -extern "C" -JNIEXPORT jint JNICALL -Java_com_eurekateam_samsungextras_interfaces_Battery_getGeneralBatteryStats(JNIEnv *env,__unused jobject obj, jint id) { - /** - * id: - * 1 = BATTERY_CAPACITY_MAX - * 2 = BATTERY_CAPACITY_CURRENT (%) - * 3 = BATTERY_CAPACITY_CURRENT (mAh) - * 4 = CHARGING_STATE - * 5 = BATTERY_TEMP - * 6 = BATTERY_CURRENT - */ - android::sp service = IBattery::getService(); - int ret; - switch (id) { - case 1: - ret = service->getBatteryStats(SysfsType::CAPACITY_MAX) / 1000; - break; - case 2: - ret = service->getBatteryStats(SysfsType::CAPACITY_CURRENT); - break; - case 3: - ret = (float) service->getBatteryStats(SysfsType::CAPACITY_CURRENT) * - (float) service->getBatteryStats(SysfsType::CAPACITY_MAX) / 100000; - break; - case 4: - if (service->getBatteryStats(SysfsType::CURRENT) > 0){ - ret = 1; - }else{ - ret = 0; - } - break; - case 5: - ret = service->getBatteryStats(SysfsType::TEMP) / 10; - break; - case 6: - ret = service->getBatteryStats(SysfsType::CURRENT); - break; - default: - ret = -1; - break; - } - return ret; - - +extern "C" JNIEXPORT jint JNICALL +Java_com_eurekateam_samsungextras_interfaces_Battery_getGeneralBatteryStats(JNIEnv* env, + __unused jobject obj, + jint id) { + /** + * id: + * 1 = BATTERY_CAPACITY_MAX + * 2 = BATTERY_CAPACITY_CURRENT (%) + * 3 = BATTERY_CAPACITY_CURRENT (mAh) + * 4 = CHARGING_STATE + * 5 = BATTERY_TEMP + * 6 = BATTERY_CURRENT + */ + android::sp service = IBattery::getService(); + int ret; + switch (id) { + case 1: + ret = service->getBatteryStats(SysfsType::CAPACITY_MAX) / 1000; + break; + case 2: + ret = service->getBatteryStats(SysfsType::CAPACITY_CURRENT); + break; + case 3: + ret = (float)service->getBatteryStats(SysfsType::CAPACITY_CURRENT) * + (float)service->getBatteryStats(SysfsType::CAPACITY_MAX) / 100000; + break; + case 4: + if (service->getBatteryStats(SysfsType::CURRENT) > 0) { + ret = 1; + } else { + ret = 0; + } + break; + case 5: + ret = service->getBatteryStats(SysfsType::TEMP) / 10; + break; + case 6: + ret = service->getBatteryStats(SysfsType::CURRENT); + break; + default: + ret = -1; + break; + } + return ret; } diff --git a/universal7885-common/apps/SamsungParts/jni/FlashlightBridge.cpp b/universal7885-common/apps/SamsungParts/jni/FlashlightBridge.cpp index 0c303e8..ede7913 100644 --- a/universal7885-common/apps/SamsungParts/jni/FlashlightBridge.cpp +++ b/universal7885-common/apps/SamsungParts/jni/FlashlightBridge.cpp @@ -1,68 +1,63 @@ -#include -#include -#include #include #include +#include +#include +#include #include "jni.h" -using vendor::eureka::hardware::flashlight::V1_0::IFlashlight; +using android::sp; using vendor::eureka::hardware::flashlight::V1_0::Device; using vendor::eureka::hardware::flashlight::V1_0::Enable; +using vendor::eureka::hardware::flashlight::V1_0::IFlashlight; using vendor::eureka::hardware::flashlight::V1_0::Number; -using android::sp; -extern "C" -JNIEXPORT void JNICALL -Java_com_eurekateam_samsungextras_interfaces_Flashlight_setFlash(JNIEnv *env, __unused jobject obj, - jint value) { - android::sp service = IFlashlight::getService(); - service->setFlashlightEnable(Enable::ENABLE); - switch (value) { - case 1: - service->setFlashlightWritable(Number::ONEUI); - break; - case 2: - service->setFlashlightWritable(Number::TWOUI); - break; - case 3: - service->setFlashlightWritable(Number::THREEUI); - break; - case 4: - service->setFlashlightWritable(Number::FOURUI); - break; - case 5: - service->setFlashlightWritable(Number::FIVEUI); - break; - case 6: - service->setFlashlightWritable(Number::SIXUI); - break; - case 7: - service->setFlashlightWritable(Number::SEVENUI); - break; - case 8: - service->setFlashlightWritable(Number::EIGHTUI); - break; - case 9: - service->setFlashlightWritable(Number::NINEUI); - break; - case 10: - service->setFlashlightWritable(Number::TENUI); - break; - default: - break; - - } +extern "C" JNIEXPORT void JNICALL Java_com_eurekateam_samsungextras_interfaces_Flashlight_setFlash( + JNIEnv* env, __unused jobject obj, jint value) { + android::sp service = IFlashlight::getService(); + service->setFlashlightEnable(Enable::ENABLE); + switch (value) { + case 1: + service->setFlashlightWritable(Number::ONEUI); + break; + case 2: + service->setFlashlightWritable(Number::TWOUI); + break; + case 3: + service->setFlashlightWritable(Number::THREEUI); + break; + case 4: + service->setFlashlightWritable(Number::FOURUI); + break; + case 5: + service->setFlashlightWritable(Number::FIVEUI); + break; + case 6: + service->setFlashlightWritable(Number::SIXUI); + break; + case 7: + service->setFlashlightWritable(Number::SEVENUI); + break; + case 8: + service->setFlashlightWritable(Number::EIGHTUI); + break; + case 9: + service->setFlashlightWritable(Number::NINEUI); + break; + case 10: + service->setFlashlightWritable(Number::TENUI); + break; + default: + break; + } } -extern "C" -JNIEXPORT jint JNICALL -Java_com_eurekateam_samsungextras_interfaces_Flashlight_getFlash(JNIEnv *env, jobject clazz, - jint isA10) { - android::sp service = IFlashlight::getService(); - int ret; - if (isA10 == 1){ +extern "C" JNIEXPORT jint JNICALL Java_com_eurekateam_samsungextras_interfaces_Flashlight_getFlash( + JNIEnv* env, jobject clazz, jint isA10) { + android::sp service = IFlashlight::getService(); + int ret; + if (isA10 == 1) { ret = service->readFlashlightstats(Device::A10); - }else{ + } else { ret = service->readFlashlightstats(Device::NOTA10); - } - return ret; + } + return ret; } diff --git a/universal7885-common/apps/SamsungParts/jni/GPUBridge.cpp b/universal7885-common/apps/SamsungParts/jni/GPUBridge.cpp index 326bfdd..6d06490 100644 --- a/universal7885-common/apps/SamsungParts/jni/GPUBridge.cpp +++ b/universal7885-common/apps/SamsungParts/jni/GPUBridge.cpp @@ -1,28 +1,26 @@ -#include -#include -#include #include #include +#include +#include +#include #include "jni.h" -using vendor::eureka::hardware::gpu::V1_0::IGpu; -using vendor::eureka::hardware::gpu::V1_0::Enable; using android::sp; - -extern "C" -JNIEXPORT void JNICALL -Java_com_eurekateam_samsungextras_interfaces_GPU_setGPU(JNIEnv *env, jclass clazz, jint enable) { - android::sp service = IGpu::getService(); - if (enable == 1){ - service->setGpuWritable(Enable::ENABLE); - }else{ - service->setGpuWritable(Enable::DISABLE); - } +using vendor::eureka::hardware::gpu::V1_0::Enable; +using vendor::eureka::hardware::gpu::V1_0::IGpu; + +extern "C" JNIEXPORT void JNICALL +Java_com_eurekateam_samsungextras_interfaces_GPU_setGPU(JNIEnv* env, jclass clazz, jint enable) { + android::sp service = IGpu::getService(); + if (enable == 1) { + service->setGpuWritable(Enable::ENABLE); + } else { + service->setGpuWritable(Enable::DISABLE); + } } -extern "C" -JNIEXPORT jint JNICALL -Java_com_eurekateam_samsungextras_interfaces_GPU_getGPU(JNIEnv *env, jclass clazz) { - android::sp service = IGpu::getService(); - int ret = service->readGpustats(); - return ret; +extern "C" JNIEXPORT jint JNICALL +Java_com_eurekateam_samsungextras_interfaces_GPU_getGPU(JNIEnv* env, jclass clazz) { + android::sp service = IGpu::getService(); + int ret = service->readGpustats(); + return ret; } diff --git a/universal7885-common/apps/SamsungParts/jni/SELinuxBridge.cpp b/universal7885-common/apps/SamsungParts/jni/SELinuxBridge.cpp index 63b8103..76eba2c 100644 --- a/universal7885-common/apps/SamsungParts/jni/SELinuxBridge.cpp +++ b/universal7885-common/apps/SamsungParts/jni/SELinuxBridge.cpp @@ -1,18 +1,17 @@ -#include -#include -#include #include #include +#include +#include +#include #include "jni.h" -using vendor::eureka::security::selinux::V1_0::ISELinux; -using vendor::eureka::security::selinux::V1_0::Enable; using android::sp; +using vendor::eureka::security::selinux::V1_0::Enable; +using vendor::eureka::security::selinux::V1_0::ISELinux; -extern "C" -JNIEXPORT jint JNICALL -Java_com_eurekateam_samsungextras_interfaces_SELinux_getSELinux(JNIEnv *env, jclass clazz) { - android::sp service = ISELinux::getService(); - int ret = service->readSELinuxstats(); - return ret; +extern "C" JNIEXPORT jint JNICALL +Java_com_eurekateam_samsungextras_interfaces_SELinux_getSELinux(JNIEnv* env, jclass clazz) { + android::sp service = ISELinux::getService(); + int ret = service->readSELinuxstats(); + return ret; } diff --git a/universal7885-common/bluetooth/bdroid_buildcfg.h b/universal7885-common/bluetooth/bdroid_buildcfg.h index 64e2c2d..7b233c6 100644 --- a/universal7885-common/bluetooth/bdroid_buildcfg.h +++ b/universal7885-common/bluetooth/bdroid_buildcfg.h @@ -6,21 +6,15 @@ #include #include -static inline const char* BtmGetDefaultName() -{ +static inline const char* BtmGetDefaultName() { char product_device[PROPERTY_VALUE_MAX]; property_get("ro.product.device", product_device, ""); - - if (strstr(product_device, "a10")) - return "Galaxy A10"; - if (strstr(product_device, "a20e")) - return "Galaxy A20e"; - if (strstr(product_device, "a20")) - return "Galaxy A20"; - if (strstr(product_device, "a30")) - return "Galaxy A30"; - if (strstr(product_device, "a40")) - return "Galaxy A40"; + + if (strstr(product_device, "a10")) return "Galaxy A10"; + if (strstr(product_device, "a20e")) return "Galaxy A20e"; + if (strstr(product_device, "a20")) return "Galaxy A20"; + if (strstr(product_device, "a30")) return "Galaxy A30"; + if (strstr(product_device, "a40")) return "Galaxy A40"; // Fallback to Generic return "Samsung Galaxy"; } diff --git a/universal7885-common/hidl/fingerprint/BiometricsFingerprint.cpp b/universal7885-common/hidl/fingerprint/BiometricsFingerprint.cpp index b21e20d..989559b 100644 --- a/universal7885-common/hidl/fingerprint/BiometricsFingerprint.cpp +++ b/universal7885-common/hidl/fingerprint/BiometricsFingerprint.cpp @@ -24,9 +24,9 @@ #include "BiometricsFingerprint.h" #include -#include #include #include +#include #ifdef HAS_FINGERPRINT_GESTURES #include @@ -58,9 +58,8 @@ BiometricsFingerprint::BiometricsFingerprint() : mClientCallback(nullptr) { return; } - int err = ioctl(uinputFd, UI_SET_EVBIT, EV_KEY) | - ioctl(uinputFd, UI_SET_KEYBIT, KEY_UP) | - ioctl(uinputFd, UI_SET_KEYBIT, KEY_DOWN); + int err = ioctl(uinputFd, UI_SET_EVBIT, EV_KEY) | ioctl(uinputFd, UI_SET_KEYBIT, KEY_UP) | + ioctl(uinputFd, UI_SET_KEYBIT, KEY_DOWN); if (err != 0) { LOG(ERROR) << "Unable to enable key events"; return; @@ -71,14 +70,14 @@ BiometricsFingerprint::BiometricsFingerprint() : mClientCallback(nullptr) { err = write(uinputFd, &uidev, sizeof(uidev)); if (err < 0) { - LOG(ERROR) << "Write user device to uinput node failed"; - return; + LOG(ERROR) << "Write user device to uinput node failed"; + return; } err = ioctl(uinputFd, UI_DEV_CREATE); if (err < 0) { - LOG(ERROR) << "Unable to create uinput device"; - return; + LOG(ERROR) << "Unable to create uinput device"; + return; } LOG(INFO) << "Successfully registered uinput-sec-fp for fingerprint gestures"; @@ -200,7 +199,7 @@ FingerprintAcquiredInfo BiometricsFingerprint::VendorAcquiredFilter(int32_t info } Return BiometricsFingerprint::setNotify( - const sp& clientCallback) { + const sp& clientCallback) { std::lock_guard lock(mClientCallbackMutex); mClientCallback = clientCallback; // This is here because HAL 2.3 doesn't have a way to propagate a @@ -286,33 +285,33 @@ bool BiometricsFingerprint::openHal() { if (handle) { int err; - ss_fingerprint_close = - reinterpret_cast(dlsym(handle, "ss_fingerprint_close")); + ss_fingerprint_close = reinterpret_cast( + dlsym(handle, "ss_fingerprint_close")); ss_fingerprint_open = - reinterpret_cast(dlsym(handle, "ss_fingerprint_open")); + reinterpret_cast(dlsym(handle, "ss_fingerprint_open")); ss_set_notify_callback = reinterpret_cast( - dlsym(handle, "ss_set_notify_callback")); + dlsym(handle, "ss_set_notify_callback")); ss_fingerprint_pre_enroll = reinterpret_cast( - dlsym(handle, "ss_fingerprint_pre_enroll")); - ss_fingerprint_enroll = - reinterpret_cast(dlsym(handle, "ss_fingerprint_enroll")); + dlsym(handle, "ss_fingerprint_pre_enroll")); + ss_fingerprint_enroll = reinterpret_cast( + dlsym(handle, "ss_fingerprint_enroll")); ss_fingerprint_post_enroll = reinterpret_cast( - dlsym(handle, "ss_fingerprint_post_enroll")); + dlsym(handle, "ss_fingerprint_post_enroll")); ss_fingerprint_get_auth_id = reinterpret_cast( - dlsym(handle, "ss_fingerprint_get_auth_id")); - ss_fingerprint_cancel = - reinterpret_cast(dlsym(handle, "ss_fingerprint_cancel")); + dlsym(handle, "ss_fingerprint_get_auth_id")); + ss_fingerprint_cancel = reinterpret_cast( + dlsym(handle, "ss_fingerprint_cancel")); ss_fingerprint_enumerate = reinterpret_cast( - dlsym(handle, "ss_fingerprint_enumerate")); - ss_fingerprint_remove = - reinterpret_cast(dlsym(handle, "ss_fingerprint_remove")); + dlsym(handle, "ss_fingerprint_enumerate")); + ss_fingerprint_remove = reinterpret_cast( + dlsym(handle, "ss_fingerprint_remove")); ss_fingerprint_set_active_group = reinterpret_cast( - dlsym(handle, "ss_fingerprint_set_active_group")); + dlsym(handle, "ss_fingerprint_set_active_group")); ss_fingerprint_authenticate = reinterpret_cast( - dlsym(handle, "ss_fingerprint_authenticate")); + dlsym(handle, "ss_fingerprint_authenticate")); ss_fingerprint_request = reinterpret_cast( - dlsym(handle, "ss_fingerprint_request")); + dlsym(handle, "ss_fingerprint_request")); if ((err = ss_fingerprint_open(nullptr)) != 0) { LOG(ERROR) << "Can't open fingerprint, error: " << err; @@ -332,7 +331,7 @@ bool BiometricsFingerprint::openHal() { void BiometricsFingerprint::notify(const fingerprint_msg_t* msg) { BiometricsFingerprint* thisPtr = - static_cast(BiometricsFingerprint::getInstance()); + static_cast(BiometricsFingerprint::getInstance()); std::lock_guard lock(thisPtr->mClientCallbackMutex); if (thisPtr == nullptr || thisPtr->mClientCallback == nullptr) { LOG(ERROR) << "Receiving callbacks before the client callback is registered."; @@ -355,7 +354,7 @@ void BiometricsFingerprint::notify(const fingerprint_msg_t* msg) { } int32_t vendorCode = 0; FingerprintAcquiredInfo result = - VendorAcquiredFilter(msg->data.acquired.acquired_info, &vendorCode); + VendorAcquiredFilter(msg->data.acquired.acquired_info, &vendorCode); LOG(DEBUG) << "onAcquired(" << static_cast(result) << ")"; if (!thisPtr->mClientCallback->onAcquired(devId, result, vendorCode).isOk()) { LOG(ERROR) << "failed to invoke fingerprint onAcquired callback"; @@ -364,10 +363,10 @@ void BiometricsFingerprint::notify(const fingerprint_msg_t* msg) { case FINGERPRINT_TEMPLATE_ENROLLING: #ifdef USES_PERCENTAGE_SAMPLES const_cast(msg)->data.enroll.samples_remaining = - 100 - msg->data.enroll.samples_remaining; + 100 - msg->data.enroll.samples_remaining; #endif #ifdef CALL_CANCEL_ON_ENROLL_COMPLETION - if(msg->data.enroll.samples_remaining == 0) { + if (msg->data.enroll.samples_remaining == 0) { thisPtr->ss_fingerprint_cancel(); } #endif @@ -375,9 +374,10 @@ void BiometricsFingerprint::notify(const fingerprint_msg_t* msg) { << ", gid=" << msg->data.enroll.finger.gid << ", rem=" << msg->data.enroll.samples_remaining << ")"; if (!thisPtr->mClientCallback - ->onEnrollResult(devId, msg->data.enroll.finger.fid, - msg->data.enroll.finger.gid, msg->data.enroll.samples_remaining) - .isOk()) { + ->onEnrollResult(devId, msg->data.enroll.finger.fid, + msg->data.enroll.finger.gid, + msg->data.enroll.samples_remaining) + .isOk()) { LOG(ERROR) << "failed to invoke fingerprint onEnrollResult callback"; } break; @@ -386,9 +386,10 @@ void BiometricsFingerprint::notify(const fingerprint_msg_t* msg) { << ", gid=" << msg->data.removed.finger.gid << ", rem=" << msg->data.removed.remaining_templates << ")"; if (!thisPtr->mClientCallback - ->onRemoved(devId, msg->data.removed.finger.fid, msg->data.removed.finger.gid, - msg->data.removed.remaining_templates) - .isOk()) { + ->onRemoved(devId, msg->data.removed.finger.fid, + msg->data.removed.finger.gid, + msg->data.removed.remaining_templates) + .isOk()) { LOG(ERROR) << "failed to invoke fingerprint onRemoved callback"; } break; @@ -398,19 +399,20 @@ void BiometricsFingerprint::notify(const fingerprint_msg_t* msg) { if (msg->data.authenticated.finger.fid != 0) { const uint8_t* hat = reinterpret_cast(&msg->data.authenticated.hat); const hidl_vec token( - std::vector(hat, hat + sizeof(msg->data.authenticated.hat))); + std::vector(hat, hat + sizeof(msg->data.authenticated.hat))); if (!thisPtr->mClientCallback - ->onAuthenticated(devId, msg->data.authenticated.finger.fid, - msg->data.authenticated.finger.gid, token) - .isOk()) { + ->onAuthenticated(devId, msg->data.authenticated.finger.fid, + msg->data.authenticated.finger.gid, token) + .isOk()) { LOG(ERROR) << "failed to invoke fingerprint onAuthenticated callback"; } } else { // Not a recognized fingerprint if (!thisPtr->mClientCallback - ->onAuthenticated(devId, msg->data.authenticated.finger.fid, - msg->data.authenticated.finger.gid, hidl_vec()) - .isOk()) { + ->onAuthenticated(devId, msg->data.authenticated.finger.fid, + msg->data.authenticated.finger.gid, + hidl_vec()) + .isOk()) { LOG(ERROR) << "failed to invoke fingerprint onAuthenticated callback"; } } @@ -420,10 +422,10 @@ void BiometricsFingerprint::notify(const fingerprint_msg_t* msg) { << ", gid=" << msg->data.enumerated.finger.gid << ", rem=" << msg->data.enumerated.remaining_templates << ")"; if (!thisPtr->mClientCallback - ->onEnumerate(devId, msg->data.enumerated.finger.fid, - msg->data.enumerated.finger.gid, - msg->data.enumerated.remaining_templates) - .isOk()) { + ->onEnumerate(devId, msg->data.enumerated.finger.fid, + msg->data.enumerated.finger.gid, + msg->data.enumerated.remaining_templates) + .isOk()) { LOG(ERROR) << "failed to invoke fingerprint onEnumerate callback"; } break; @@ -436,8 +438,7 @@ void BiometricsFingerprint::handleEvent(int eventCode) { case SEM_FINGERPRINT_EVENT_GESTURE_SWIPE_DOWN: case SEM_FINGERPRINT_EVENT_GESTURE_SWIPE_UP: struct input_event event {}; - int keycode = eventCode == SEM_FINGERPRINT_EVENT_GESTURE_SWIPE_UP ? - KEY_UP : KEY_DOWN; + int keycode = eventCode == SEM_FINGERPRINT_EVENT_GESTURE_SWIPE_UP ? KEY_UP : KEY_DOWN; int err; // Report the key @@ -479,7 +480,7 @@ void BiometricsFingerprint::handleEvent(int eventCode) { LOG(ERROR) << "Write EV_SYN to uinput node failed"; return; } - break; + break; #endif } } @@ -496,8 +497,8 @@ int BiometricsFingerprint::waitForSensor(std::chrono::milliseconds pollWait, int sensorStatus = SEM_SENSOR_STATUS_WORKING; std::chrono::milliseconds timeWaited = 0ms; while (sensorStatus != SEM_SENSOR_STATUS_OK) { - if (sensorStatus == SEM_SENSOR_STATUS_CALIBRATION_ERROR - || sensorStatus == SEM_SENSOR_STATUS_ERROR){ + if (sensorStatus == SEM_SENSOR_STATUS_CALIBRATION_ERROR || + sensorStatus == SEM_SENSOR_STATUS_ERROR) { return -1; } if (timeWaited >= timeOut) { diff --git a/universal7885-common/hidl/fingerprint/BiometricsFingerprint.h b/universal7885-common/hidl/fingerprint/BiometricsFingerprint.h index 934c15f..58e0844 100644 --- a/universal7885-common/hidl/fingerprint/BiometricsFingerprint.h +++ b/universal7885-common/hidl/fingerprint/BiometricsFingerprint.h @@ -24,12 +24,12 @@ #include #endif +#include +#include #include #include #include #include -#include -#include #include "VendorConstants.h" @@ -47,11 +47,11 @@ using ::android::hardware::hidl_string; using ::android::hardware::hidl_vec; using ::android::hardware::Return; using ::android::hardware::Void; -using ::android::hardware::biometrics::fingerprint::V2_3::IBiometricsFingerprint; -using ::android::hardware::biometrics::fingerprint::V2_1::IBiometricsFingerprintClientCallback; using ::android::hardware::biometrics::fingerprint::V2_1::FingerprintAcquiredInfo; using ::android::hardware::biometrics::fingerprint::V2_1::FingerprintError; +using ::android::hardware::biometrics::fingerprint::V2_1::IBiometricsFingerprintClientCallback; using ::android::hardware::biometrics::fingerprint::V2_1::RequestStatus; +using ::android::hardware::biometrics::fingerprint::V2_3::IBiometricsFingerprint; struct BiometricsFingerprint : public IBiometricsFingerprint { BiometricsFingerprint(); @@ -60,9 +60,10 @@ struct BiometricsFingerprint : public IBiometricsFingerprint { // Method to wrap legacy HAL with BiometricsFingerprint class static IBiometricsFingerprint* getInstance(); - // Methods from ::android::hardware::biometrics::fingerprint::V2_3::IBiometricsFingerprint follow. + // Methods from ::android::hardware::biometrics::fingerprint::V2_3::IBiometricsFingerprint + // follow. Return setNotify( - const sp& clientCallback) override; + const sp& clientCallback) override; Return preEnroll() override; Return enroll(const hidl_array& hat, uint32_t gid, uint32_t timeoutSec) override; @@ -76,15 +77,15 @@ struct BiometricsFingerprint : public IBiometricsFingerprint { Return isUdfps(uint32_t sensorID) override; Return onFingerDown(uint32_t x, uint32_t y, float minor, float major) override; Return onFingerUp() override; - Return onShowUdfpsOverlay(){ return Void();} - Return onHideUdfpsOverlay(){ return Void();} + Return onShowUdfpsOverlay() { return Void(); } + Return onHideUdfpsOverlay() { return Void(); } private: bool openHal(); int request(int cmd, int param); int waitForSensor(std::chrono::milliseconds pollWait, std::chrono::milliseconds timeOut); static void notify( - const fingerprint_msg_t* msg); /* Static callback for legacy HAL implementation */ + const fingerprint_msg_t* msg); /* Static callback for legacy HAL implementation */ void handleEvent(int eventCode); static Return ErrorFilter(int32_t error); static FingerprintError VendorErrorFilter(int32_t error, int32_t* vendorCode); @@ -111,7 +112,8 @@ struct BiometricsFingerprint : public IBiometricsFingerprint { int (*ss_fingerprint_remove)(uint32_t gid, uint32_t fid); int (*ss_fingerprint_set_active_group)(uint32_t gid, const char* store_path); int (*ss_fingerprint_authenticate)(uint64_t operation_id, uint32_t gid); - int (*ss_fingerprint_request)(uint32_t cmd, char *inBuf, uint32_t inBuf_length, char *outBuf, uint32_t outBuf_length, uint32_t param); + int (*ss_fingerprint_request)(uint32_t cmd, char* inBuf, uint32_t inBuf_length, char* outBuf, + uint32_t outBuf_length, uint32_t param); }; } // namespace implementation diff --git a/universal7885-common/hidl/fingerprint/VendorConstants.h b/universal7885-common/hidl/fingerprint/VendorConstants.h index 3af6c69..212eddd 100644 --- a/universal7885-common/hidl/fingerprint/VendorConstants.h +++ b/universal7885-common/hidl/fingerprint/VendorConstants.h @@ -101,4 +101,4 @@ #define SEM_SENSOR_STATUS_OK 100040 #define SEM_SENSOR_STATUS_WORKING 100041 -#endif // SAMSUNG_FINGERPRINT_CONSTANTS_H +#endif // SAMSUNG_FINGERPRINT_CONSTANTS_H diff --git a/universal7885-common/hidl/keymaster/service.cpp b/universal7885-common/hidl/keymaster/service.cpp index 7086273..5116984 100644 --- a/universal7885-common/hidl/keymaster/service.cpp +++ b/universal7885-common/hidl/keymaster/service.cpp @@ -37,7 +37,7 @@ IKeymasterDevice* CreateSKeymasterDevice(SecurityLevel securityLevel); int main() { IKeymasterDevice* keymaster = - skeymaster::CreateSKeymasterDevice(SecurityLevel::TRUSTED_ENVIRONMENT); + skeymaster::CreateSKeymasterDevice(SecurityLevel::TRUSTED_ENVIRONMENT); configureRpcThreadpool(1, true); diff --git a/universal7885-common/hidl/sensors/Sensors.cpp b/universal7885-common/hidl/sensors/Sensors.cpp index dc54bb5..9998bbd 100644 --- a/universal7885-common/hidl/sensors/Sensors.cpp +++ b/universal7885-common/hidl/sensors/Sensors.cpp @@ -37,7 +37,7 @@ namespace implementation { static bool UseMultiHal() { const std::string& name = MULTI_HAL_CONFIG_FILE_PATH; struct stat buffer; - return (stat (name.c_str(), &buffer) == 0); + return (stat(name.c_str(), &buffer) == 0); } static Result ResultFromStatus(status_t err) { @@ -55,28 +55,20 @@ static Result ResultFromStatus(status_t err) { } } -Sensors::Sensors() - : mInitCheck(NO_INIT), - mSensorModule(nullptr), - mSensorDevice(nullptr) { +Sensors::Sensors() : mInitCheck(NO_INIT), mSensorModule(nullptr), mSensorDevice(nullptr) { status_t err = OK; if (UseMultiHal()) { mSensorModule = ::get_multi_hal_module_info(); } else { - err = hw_get_module( - SENSORS_HARDWARE_MODULE_ID, - (hw_module_t const **)&mSensorModule); + err = hw_get_module(SENSORS_HARDWARE_MODULE_ID, (hw_module_t const**)&mSensorModule); } if (mSensorModule == NULL) { err = UNKNOWN_ERROR; } if (err != OK) { - LOG(ERROR) << "Couldn't load " - << SENSORS_HARDWARE_MODULE_ID - << " module (" - << strerror(-err) - << ")"; + LOG(ERROR) << "Couldn't load " << SENSORS_HARDWARE_MODULE_ID << " module (" + << strerror(-err) << ")"; mInitCheck = err; return; @@ -85,11 +77,8 @@ Sensors::Sensors() err = sensors_open_1(&mSensorModule->common, &mSensorDevice); if (err != OK) { - LOG(ERROR) << "Couldn't open device for module " - << SENSORS_HARDWARE_MODULE_ID - << " (" - << strerror(-err) - << ")"; + LOG(ERROR) << "Couldn't open device for module " << SENSORS_HARDWARE_MODULE_ID << " (" + << strerror(-err) << ")"; mInitCheck = err; return; @@ -119,15 +108,15 @@ status_t Sensors::initCheck() const { } Return Sensors::getSensorsList(getSensorsList_cb _hidl_cb) { - sensor_t const *list; + sensor_t const* list; size_t count = mSensorModule->get_sensors_list(mSensorModule, &list); hidl_vec out; out.resize(count); for (size_t i = 0; i < count; ++i) { - const sensor_t *src = &list[i]; - SensorInfo *dst = &out[i]; + const sensor_t* src = &list[i]; + SensorInfo* dst = &out[i]; convertFromSensor(*src, dst); @@ -166,31 +155,26 @@ int Sensors::getHalDeviceVersion() const { } Return Sensors::setOperationMode(OperationMode mode) { - if (getHalDeviceVersion() < SENSORS_DEVICE_API_VERSION_1_4 - || mSensorModule->set_operation_mode == nullptr) { + if (getHalDeviceVersion() < SENSORS_DEVICE_API_VERSION_1_4 || + mSensorModule->set_operation_mode == nullptr) { return Result::INVALID_OPERATION; } return ResultFromStatus(mSensorModule->set_operation_mode((uint32_t)mode)); } -Return Sensors::activate( - int32_t sensor_handle, bool enabled) { - return ResultFromStatus( - mSensorDevice->activate( - reinterpret_cast(mSensorDevice), - sensor_handle, - enabled)); +Return Sensors::activate(int32_t sensor_handle, bool enabled) { + return ResultFromStatus(mSensorDevice->activate( + reinterpret_cast(mSensorDevice), sensor_handle, enabled)); } Return Sensors::poll(int32_t maxCount, poll_cb _hidl_cb) { - hidl_vec out; hidl_vec dynamicSensorsAdded; std::unique_ptr data; int err = android::NO_ERROR; - { // scope of reentry lock + { // scope of reentry lock // This enforces a single client, meaning that a maximum of one client can call poll(). // If this function is re-entred, it means that we are stuck in a state that may prevent @@ -200,11 +184,11 @@ Return Sensors::poll(int32_t maxCount, poll_cb _hidl_cb) { // // This function must not call _hidl_cb(...) or return until there is no risk of blocking. std::unique_lock lock(mPollLock, std::try_to_lock); - if(!lock.owns_lock()){ + if (!lock.owns_lock()) { // cannot get the lock, hidl service will go into deadlock if it is not restarted. // This is guaranteed to not trigger in passthrough mode. - LOG(ERROR) << - "ISensors::poll() re-entry. I do not know what to do except killing myself."; + LOG(ERROR) + << "ISensors::poll() re-entry. I do not know what to do except killing myself."; ::exit(-1); } @@ -213,9 +197,8 @@ Return Sensors::poll(int32_t maxCount, poll_cb _hidl_cb) { } else { int bufferSize = maxCount <= kPollMaxBufferSize ? maxCount : kPollMaxBufferSize; data.reset(new sensors_event_t[bufferSize]); - err = mSensorDevice->poll( - reinterpret_cast(mSensorDevice), - data.get(), bufferSize); + err = mSensorDevice->poll(reinterpret_cast(mSensorDevice), + data.get(), bufferSize); } } @@ -231,7 +214,7 @@ Return Sensors::poll(int32_t maxCount, poll_cb _hidl_cb) { continue; } - const dynamic_sensor_meta_event_t *dyn = &data[i].dynamic_sensor_meta; + const dynamic_sensor_meta_event_t* dyn = &data[i].dynamic_sensor_meta; if (!dyn->connected) { continue; @@ -256,17 +239,10 @@ Return Sensors::poll(int32_t maxCount, poll_cb _hidl_cb) { return Void(); } -Return Sensors::batch( - int32_t sensor_handle, - int64_t sampling_period_ns, - int64_t max_report_latency_ns) { - return ResultFromStatus( - mSensorDevice->batch( - mSensorDevice, - sensor_handle, - 0, /*flags*/ - sampling_period_ns, - max_report_latency_ns)); +Return Sensors::batch(int32_t sensor_handle, int64_t sampling_period_ns, + int64_t max_report_latency_ns) { + return ResultFromStatus(mSensorDevice->batch(mSensorDevice, sensor_handle, 0, /*flags*/ + sampling_period_ns, max_report_latency_ns)); } Return Sensors::flush(int32_t sensor_handle) { @@ -274,22 +250,21 @@ Return Sensors::flush(int32_t sensor_handle) { } Return Sensors::injectSensorData(const Event& event) { - if (getHalDeviceVersion() < SENSORS_DEVICE_API_VERSION_1_4 - || mSensorDevice->inject_sensor_data == nullptr) { + if (getHalDeviceVersion() < SENSORS_DEVICE_API_VERSION_1_4 || + mSensorDevice->inject_sensor_data == nullptr) { return Result::INVALID_OPERATION; } sensors_event_t out; convertToSensorEvent(event, &out); - return ResultFromStatus( - mSensorDevice->inject_sensor_data(mSensorDevice, &out)); + return ResultFromStatus(mSensorDevice->inject_sensor_data(mSensorDevice, &out)); } -Return Sensors::registerDirectChannel( - const SharedMemInfo& mem, registerDirectChannel_cb _hidl_cb) { - if (mSensorDevice->register_direct_channel == nullptr - || mSensorDevice->config_direct_report == nullptr) { +Return Sensors::registerDirectChannel(const SharedMemInfo& mem, + registerDirectChannel_cb _hidl_cb) { + if (mSensorDevice->register_direct_channel == nullptr || + mSensorDevice->config_direct_report == nullptr) { // HAL does not support _hidl_cb(Result::INVALID_OPERATION, -1); return Void(); @@ -297,8 +272,8 @@ Return Sensors::registerDirectChannel( sensors_direct_mem_t m; if (!convertFromSharedMemInfo(mem, &m)) { - _hidl_cb(Result::BAD_VALUE, -1); - return Void(); + _hidl_cb(Result::BAD_VALUE, -1); + return Void(); } int err = mSensorDevice->register_direct_channel(mSensorDevice, &m, -1); @@ -313,8 +288,8 @@ Return Sensors::registerDirectChannel( } Return Sensors::unregisterDirectChannel(int32_t channelHandle) { - if (mSensorDevice->register_direct_channel == nullptr - || mSensorDevice->config_direct_report == nullptr) { + if (mSensorDevice->register_direct_channel == nullptr || + mSensorDevice->config_direct_report == nullptr) { // HAL does not support return Result::INVALID_OPERATION; } @@ -324,26 +299,22 @@ Return Sensors::unregisterDirectChannel(int32_t channelHandle) { return Result::OK; } -Return Sensors::configDirectReport( - int32_t sensorHandle, int32_t channelHandle, RateLevel rate, - configDirectReport_cb _hidl_cb) { - if (mSensorDevice->register_direct_channel == nullptr - || mSensorDevice->config_direct_report == nullptr) { +Return Sensors::configDirectReport(int32_t sensorHandle, int32_t channelHandle, + RateLevel rate, configDirectReport_cb _hidl_cb) { + if (mSensorDevice->register_direct_channel == nullptr || + mSensorDevice->config_direct_report == nullptr) { // HAL does not support _hidl_cb(Result::INVALID_OPERATION, -1); return Void(); } - sensors_direct_cfg_t cfg = { - .rate_level = convertFromRateLevel(rate) - }; + sensors_direct_cfg_t cfg = {.rate_level = convertFromRateLevel(rate)}; if (cfg.rate_level < 0) { _hidl_cb(Result::BAD_VALUE, -1); return Void(); } - int err = mSensorDevice->config_direct_report(mSensorDevice, - sensorHandle, channelHandle, &cfg); + int err = mSensorDevice->config_direct_report(mSensorDevice, sensorHandle, channelHandle, &cfg); if (rate == RateLevel::STOP) { _hidl_cb(ResultFromStatus(err), -1); @@ -354,20 +325,18 @@ Return Sensors::configDirectReport( } // static -void Sensors::convertFromSensorEvents( - size_t count, - const sensors_event_t *srcArray, - hidl_vec *dstVec) { +void Sensors::convertFromSensorEvents(size_t count, const sensors_event_t* srcArray, + hidl_vec* dstVec) { for (size_t i = 0; i < count; ++i) { - const sensors_event_t &src = srcArray[i]; - Event *dst = &(*dstVec)[i]; + const sensors_event_t& src = srcArray[i]; + Event* dst = &(*dstVec)[i]; convertFromSensorEvent(src, dst); } } -ISensors *HIDL_FETCH_ISensors(const char * /* hal */) { - Sensors *sensors = new Sensors; +ISensors* HIDL_FETCH_ISensors(const char* /* hal */) { + Sensors* sensors = new Sensors; if (sensors->initCheck() != OK) { delete sensors; sensors = nullptr; diff --git a/universal7885-common/hidl/sensors/Sensors.h b/universal7885-common/hidl/sensors/Sensors.h index a43a00d..c1138e7 100644 --- a/universal7885-common/hidl/sensors/Sensors.h +++ b/universal7885-common/hidl/sensors/Sensors.h @@ -29,7 +29,6 @@ namespace sensors { namespace V1_0 { namespace implementation { - struct Sensors : public ::android::hardware::sensors::V1_0::ISensors { Sensors(); @@ -39,45 +38,41 @@ struct Sensors : public ::android::hardware::sensors::V1_0::ISensors { Return setOperationMode(OperationMode mode) override; - Return activate( - int32_t sensor_handle, bool enabled) override; + Return activate(int32_t sensor_handle, bool enabled) override; Return poll(int32_t maxCount, poll_cb _hidl_cb) override; - Return batch( - int32_t sensor_handle, - int64_t sampling_period_ns, - int64_t max_report_latency_ns) override; + Return batch(int32_t sensor_handle, int64_t sampling_period_ns, + int64_t max_report_latency_ns) override; Return flush(int32_t sensor_handle) override; Return injectSensorData(const Event& event) override; - Return registerDirectChannel( - const SharedMemInfo& mem, registerDirectChannel_cb _hidl_cb) override; + Return registerDirectChannel(const SharedMemInfo& mem, + registerDirectChannel_cb _hidl_cb) override; Return unregisterDirectChannel(int32_t channelHandle) override; - Return configDirectReport( - int32_t sensorHandle, int32_t channelHandle, RateLevel rate, - configDirectReport_cb _hidl_cb) override; + Return configDirectReport(int32_t sensorHandle, int32_t channelHandle, RateLevel rate, + configDirectReport_cb _hidl_cb) override; -private: + private: static constexpr int32_t kPollMaxBufferSize = 128; status_t mInitCheck; - sensors_module_t *mSensorModule; - sensors_poll_device_1_t *mSensorDevice; + sensors_module_t* mSensorModule; + sensors_poll_device_1_t* mSensorDevice; std::mutex mPollLock; int getHalDeviceVersion() const; - static void convertFromSensorEvents( - size_t count, const sensors_event_t *src, hidl_vec *dst); + static void convertFromSensorEvents(size_t count, const sensors_event_t* src, + hidl_vec* dst); DISALLOW_COPY_AND_ASSIGN(Sensors); }; -extern "C" ISensors *HIDL_FETCH_ISensors(const char *name); +extern "C" ISensors* HIDL_FETCH_ISensors(const char* name); } // namespace implementation } // namespace V1_0 diff --git a/universal7885-common/init/init_universal7885.cpp b/universal7885-common/init/init_universal7885.cpp index 78b5fb4..86ddea8 100644 --- a/universal7885-common/init/init_universal7885.cpp +++ b/universal7885-common/init/init_universal7885.cpp @@ -30,8 +30,8 @@ #define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ #include -#include #include +#include #include "property_service.h" #include "vendor_init.h" @@ -40,28 +40,23 @@ using android::base::GetProperty; using std::string; std::vector ro_props_default_source_order = { - "", - "odm.", - "product.", - "system.", - "system_ext.", - "vendor.", + "", "odm.", "product.", "system.", "system_ext.", "vendor.", }; void property_override(char const prop[], char const value[], bool add = true) { - prop_info *pi; + prop_info* pi; - pi = (prop_info*) __system_property_find(prop); + pi = (prop_info*)__system_property_find(prop); if (pi) __system_property_update(pi, value, strlen(value)); else if (add) __system_property_add(prop, strlen(prop), value, strlen(value)); } -void set_ro_build_prop(const std::string &prop, const std::string &value, bool product = true) { +void set_ro_build_prop(const std::string& prop, const std::string& value, bool product = true) { string prop_name; - for (const auto &source : ro_props_default_source_order) { + for (const auto& source : ro_props_default_source_order) { if (product) prop_name = "ro.product." + source + prop; else @@ -71,10 +66,11 @@ void set_ro_build_prop(const std::string &prop, const std::string &value, bool p } } -bool hasEnding (std::string const &fullString, std::string const &ending) { +bool hasEnding(std::string const& fullString, std::string const& ending) { if (fullString.length() >= ending.length()) { - return (0 == fullString.compare (fullString.length() - ending.length(), ending.length(), ending)); - } else { + return (0 == + fullString.compare(fullString.length() - ending.length(), ending.length(), ending)); + } else { return false; } } @@ -83,12 +79,13 @@ void vendor_load_properties() { string model; model = GetProperty("ro.boot.product.model", ""); - if(model.empty()){ + if (model.empty()) { model = GetProperty("ro.boot.em.model", ""); } - if (hasEnding(model, "N") || hasEnding(model, "S") || hasEnding(model, "K") || model == "SM-A202F") { - property_override("ro.boot.product.hardware.sku", "NFC"); + if (hasEnding(model, "N") || hasEnding(model, "S") || hasEnding(model, "K") || + model == "SM-A202F") { + property_override("ro.boot.product.hardware.sku", "NFC"); } set_ro_build_prop("model", model); diff --git a/universal7885-common/interfaces/hardware/battery/1.0/default/Battery.cpp b/universal7885-common/interfaces/hardware/battery/1.0/default/Battery.cpp index 5b33778..5bc53f7 100644 --- a/universal7885-common/interfaces/hardware/battery/1.0/default/Battery.cpp +++ b/universal7885-common/interfaces/hardware/battery/1.0/default/Battery.cpp @@ -13,96 +13,97 @@ // limitations under the License. #include "Battery.h" -#include -#include -#include #include +#include +#include +#include namespace vendor::eureka::hardware::battery::V1_0 { // Methods from ::android::hardware::battery::V1_0::IBattery follow. Return Battery::getBatteryStats(battery::V1_0::SysfsType stats) { - std::ifstream file; - std::string filename; - switch (stats){ - case SysfsType::CAPACITY_MAX: - filename = "/sys/devices/platform/battery/power_supply/battery/charge_full"; - break; - case SysfsType::TEMP: - filename = "/sys/devices/platform/battery/power_supply/battery/batt_temp"; - break; - case SysfsType::CAPACITY_CURRENT: - filename = "/sys/devices/platform/battery/power_supply/battery/capacity"; - break; - case SysfsType::CURRENT: - filename = "/sys/devices/platform/battery/power_supply/battery/current_now"; - break; - case SysfsType::FASTCHARGE: - filename = "/sys/class/sec/switch/afc_disable"; - break; - case SysfsType::CHARGE: - filename = "/sys/devices/platform/battery/power_supply/battery/batt_slate_mode"; - break; - default: - filename = ""; - break; - } - std::string value; - int32_t intvalue; - file.open(filename); - if (file.is_open()) { - getline(file, value); - file.close(); - std::stringstream val(value); - val >> intvalue; - return intvalue; - } - return -1; -} - -Return Battery::setBatteryWritable(battery::V1_0::SysfsType stats, battery::V1_0::Number value) { - std::ofstream file; - std::string filename; - bool FastCharge = false; - switch (stats){ - case SysfsType::CAPACITY_MAX: - filename = "/sys/devices/platform/battery/power_supply/battery/charge_full"; - break; - case SysfsType::TEMP: - filename = "/sys/devices/platform/battery/power_supply/battery/batt_temp"; - break; - case SysfsType::CAPACITY_CURRENT: - filename = "/sys/devices/platform/battery/power_supply/battery/capacity"; - break; - case SysfsType::CURRENT: - filename = "/sys/devices/platform/battery/power_supply/battery/current_now"; - break; - case SysfsType::FASTCHARGE: - filename = "/sys/class/sec/switch/afc_disable"; - FastCharge = true; - break; - case SysfsType::CHARGE: - filename = "/sys/devices/platform/battery/power_supply/battery/batt_slate_mode"; - break; - default: - filename = ""; - break; - } - if(FastCharge) seteuid(ANDROID_SYSTEM_UID); - file.open(filename); - int write; - if (value == Number::ENABLE){ - write = 1; - }else{ - write = 0; - } - file << write; + std::ifstream file; + std::string filename; + switch (stats) { + case SysfsType::CAPACITY_MAX: + filename = "/sys/devices/platform/battery/power_supply/battery/charge_full"; + break; + case SysfsType::TEMP: + filename = "/sys/devices/platform/battery/power_supply/battery/batt_temp"; + break; + case SysfsType::CAPACITY_CURRENT: + filename = "/sys/devices/platform/battery/power_supply/battery/capacity"; + break; + case SysfsType::CURRENT: + filename = "/sys/devices/platform/battery/power_supply/battery/current_now"; + break; + case SysfsType::FASTCHARGE: + filename = "/sys/class/sec/switch/afc_disable"; + break; + case SysfsType::CHARGE: + filename = "/sys/devices/platform/battery/power_supply/battery/batt_slate_mode"; + break; + default: + filename = ""; + break; + } + std::string value; + int32_t intvalue; + file.open(filename); + if (file.is_open()) { + getline(file, value); file.close(); - if(FastCharge) seteuid(ANDROID_ROOT_UID); - return 0; + std::stringstream val(value); + val >> intvalue; + return intvalue; + } + return -1; } -IBattery *Battery::getInstance(void){ - return new Battery(); +Return Battery::setBatteryWritable(battery::V1_0::SysfsType stats, + battery::V1_0::Number value) { + std::ofstream file; + std::string filename; + bool FastCharge = false; + switch (stats) { + case SysfsType::CAPACITY_MAX: + filename = "/sys/devices/platform/battery/power_supply/battery/charge_full"; + break; + case SysfsType::TEMP: + filename = "/sys/devices/platform/battery/power_supply/battery/batt_temp"; + break; + case SysfsType::CAPACITY_CURRENT: + filename = "/sys/devices/platform/battery/power_supply/battery/capacity"; + break; + case SysfsType::CURRENT: + filename = "/sys/devices/platform/battery/power_supply/battery/current_now"; + break; + case SysfsType::FASTCHARGE: + filename = "/sys/class/sec/switch/afc_disable"; + FastCharge = true; + break; + case SysfsType::CHARGE: + filename = "/sys/devices/platform/battery/power_supply/battery/batt_slate_mode"; + break; + default: + filename = ""; + break; + } + if (FastCharge) seteuid(ANDROID_SYSTEM_UID); + file.open(filename); + int write; + if (value == Number::ENABLE) { + write = 1; + } else { + write = 0; + } + file << write; + file.close(); + if (FastCharge) seteuid(ANDROID_ROOT_UID); + return 0; } -} // namespace android::hardware::battery::implementation + +IBattery* Battery::getInstance(void) { + return new Battery(); +} +} // namespace vendor::eureka::hardware::battery::V1_0 diff --git a/universal7885-common/interfaces/hardware/battery/1.0/default/Battery.h b/universal7885-common/interfaces/hardware/battery/1.0/default/Battery.h index 34daf76..13bc85e 100644 --- a/universal7885-common/interfaces/hardware/battery/1.0/default/Battery.h +++ b/universal7885-common/interfaces/hardware/battery/1.0/default/Battery.h @@ -14,22 +14,22 @@ #pragma once -#include #include #include +#include #define ANDROID_SYSTEM_UID 1000 #define ANDROID_ROOT_UID 0 namespace vendor::eureka::hardware::battery::V1_0 { +using ::android::sp; using ::android::hardware::hidl_array; using ::android::hardware::hidl_memory; using ::android::hardware::hidl_string; using ::android::hardware::hidl_vec; using ::android::hardware::Return; using ::android::hardware::Void; -using ::android::sp; struct Battery : public IBattery { // Methods from ::vendor::eureka::hardware::battery::V1_0::IBattery follow. @@ -38,6 +38,5 @@ struct Battery : public IBattery { // Methods from ::android::hidl::base::V1_0::IBase follow. static IBattery* getInstance(void); - }; -} // namespace android::hardware::battery::implementation +} // namespace vendor::eureka::hardware::battery::V1_0 diff --git a/universal7885-common/interfaces/hardware/battery/1.0/default/service.cpp b/universal7885-common/interfaces/hardware/battery/1.0/default/service.cpp index 22ae43b..f656465 100644 --- a/universal7885-common/interfaces/hardware/battery/1.0/default/service.cpp +++ b/universal7885-common/interfaces/hardware/battery/1.0/default/service.cpp @@ -12,38 +12,37 @@ // See the License for the specific language governing permissions and // limitations under the License. - #define LOG_TAG "vendor.eureka.hardware.battery@1.0-service" - + #include - + #include - + #include "Battery.h" - -using vendor::eureka::hardware::battery::V1_0::IBattery; -using vendor::eureka::hardware::battery::V1_0::Battery; + +using android::sp; using android::hardware::configureRpcThreadpool; using android::hardware::joinRpcThreadpool; -using android::sp; - +using vendor::eureka::hardware::battery::V1_0::Battery; +using vendor::eureka::hardware::battery::V1_0::IBattery; + int main() { - int ret; - android::sp service = Battery::getInstance(); - configureRpcThreadpool(1, true /*callerWillJoin*/); - - if (service != nullptr) { - ret = service->registerAsService(); - if(ret != 0) { - ALOGE("Can't register instance of Battery HAL, nullptr"); - }else{ - ALOGI("registered Battery HAL"); - } - } else { - ALOGE("Can't create instance of Battery HAL, nullptr"); - } - - joinRpcThreadpool(); - - return -1; // should never get here + int ret; + android::sp service = Battery::getInstance(); + configureRpcThreadpool(1, true /*callerWillJoin*/); + + if (service != nullptr) { + ret = service->registerAsService(); + if (ret != 0) { + ALOGE("Can't register instance of Battery HAL, nullptr"); + } else { + ALOGI("registered Battery HAL"); + } + } else { + ALOGE("Can't create instance of Battery HAL, nullptr"); + } + + joinRpcThreadpool(); + + return -1; // should never get here } diff --git a/universal7885-common/interfaces/hardware/flashlight/1.0/default/Flashlight.cpp b/universal7885-common/interfaces/hardware/flashlight/1.0/default/Flashlight.cpp index 83b13cf..971f556 100644 --- a/universal7885-common/interfaces/hardware/flashlight/1.0/default/Flashlight.cpp +++ b/universal7885-common/interfaces/hardware/flashlight/1.0/default/Flashlight.cpp @@ -13,98 +13,98 @@ // limitations under the License. #include "Flashlight.h" -#include #include +#include #include namespace vendor::eureka::hardware::flashlight::V1_0 { // Methods from ::android::hardware::flashlight::V1_0::IFlashlight follow. Return Flashlight::setFlashlightEnable(flashlight::V1_0::Enable enable) { - std::ofstream file; - std::string writevalue; - switch (enable){ - case Enable::ENABLE: - writevalue = "1"; - break; - case Enable::DISABLE: - writevalue = "0"; - break; - default: - writevalue = ""; - break; - } - file.open("/sys/class/camera/flash/torch_brightness_lvl_enable"); - file << writevalue; - file.close(); - return 0; + std::ofstream file; + std::string writevalue; + switch (enable) { + case Enable::ENABLE: + writevalue = "1"; + break; + case Enable::DISABLE: + writevalue = "0"; + break; + default: + writevalue = ""; + break; + } + file.open("/sys/class/camera/flash/torch_brightness_lvl_enable"); + file << writevalue; + file.close(); + return 0; } Return Flashlight::setFlashlightWritable(flashlight::V1_0::Number value) { - std::ofstream file; - std::string writevalue; - switch (value){ - case Number::ONEUI: - writevalue = "1"; - break; - case Number::TWOUI: - writevalue = "2"; - break; - case Number::THREEUI: - writevalue = "3"; - break; - case Number::FOURUI: - writevalue = "4"; - break; - case Number::FIVEUI: - writevalue = "5"; - break; - case Number::SIXUI: - writevalue = "6"; - break; - case Number::SEVENUI: - writevalue = "7"; - break; - case Number::EIGHTUI: - writevalue = "8"; - break; - case Number::NINEUI: - writevalue = "9"; - break; - case Number::TENUI: - writevalue = "10"; - break; - default: - writevalue = ""; - break; - } - file.open("/sys/class/camera/flash/torch_brightness_lvl"); - file << writevalue; - file.close(); - return 0; + std::ofstream file; + std::string writevalue; + switch (value) { + case Number::ONEUI: + writevalue = "1"; + break; + case Number::TWOUI: + writevalue = "2"; + break; + case Number::THREEUI: + writevalue = "3"; + break; + case Number::FOURUI: + writevalue = "4"; + break; + case Number::FIVEUI: + writevalue = "5"; + break; + case Number::SIXUI: + writevalue = "6"; + break; + case Number::SEVENUI: + writevalue = "7"; + break; + case Number::EIGHTUI: + writevalue = "8"; + break; + case Number::NINEUI: + writevalue = "9"; + break; + case Number::TENUI: + writevalue = "10"; + break; + default: + writevalue = ""; + break; + } + file.open("/sys/class/camera/flash/torch_brightness_lvl"); + file << writevalue; + file.close(); + return 0; } Return Flashlight::readFlashlightstats(flashlight::V1_0::Device device) { - std::ifstream file; - std::string value; - int32_t intvalue; - file.open("/sys/class/camera/flash/torch_brightness_lvl"); - if (file.is_open()) { - getline(file, value); - file.close(); - std::stringstream val(value); - val >> intvalue; - if (device == Device::A10){ - return intvalue; - }else if (device == Device::NOTA10){ - return intvalue / 21; - } - // Never Here - return -1; - } - return -1; + std::ifstream file; + std::string value; + int32_t intvalue; + file.open("/sys/class/camera/flash/torch_brightness_lvl"); + if (file.is_open()) { + getline(file, value); + file.close(); + std::stringstream val(value); + val >> intvalue; + if (device == Device::A10) { + return intvalue; + } else if (device == Device::NOTA10) { + return intvalue / 21; + } + // Never Here + return -1; + } + return -1; } -IFlashlight *Flashlight::getInstance(void){ - return new Flashlight(); +IFlashlight* Flashlight::getInstance(void) { + return new Flashlight(); } -} // namespace android::hardware::flashlight::implementation +} // namespace vendor::eureka::hardware::flashlight::V1_0 diff --git a/universal7885-common/interfaces/hardware/flashlight/1.0/default/Flashlight.h b/universal7885-common/interfaces/hardware/flashlight/1.0/default/Flashlight.h index 56f2fee..bf16c42 100644 --- a/universal7885-common/interfaces/hardware/flashlight/1.0/default/Flashlight.h +++ b/universal7885-common/interfaces/hardware/flashlight/1.0/default/Flashlight.h @@ -14,19 +14,19 @@ #pragma once -#include #include #include +#include namespace vendor::eureka::hardware::flashlight::V1_0 { +using ::android::sp; using ::android::hardware::hidl_array; using ::android::hardware::hidl_memory; using ::android::hardware::hidl_string; using ::android::hardware::hidl_vec; using ::android::hardware::Return; using ::android::hardware::Void; -using ::android::sp; struct Flashlight : public IFlashlight { // Methods from ::vendor::eureka::hardware::flashlight::V1_0::IFlashlight follow. @@ -35,6 +35,5 @@ struct Flashlight : public IFlashlight { Return readFlashlightstats(Device device); // Methods from ::android::hidl::base::V1_0::IBase follow. static IFlashlight* getInstance(void); - }; -} // namespace android::hardware::flashlight::implementation +} // namespace vendor::eureka::hardware::flashlight::V1_0 diff --git a/universal7885-common/interfaces/hardware/flashlight/1.0/default/service.cpp b/universal7885-common/interfaces/hardware/flashlight/1.0/default/service.cpp index 2a748e5..7861ba1 100644 --- a/universal7885-common/interfaces/hardware/flashlight/1.0/default/service.cpp +++ b/universal7885-common/interfaces/hardware/flashlight/1.0/default/service.cpp @@ -12,38 +12,37 @@ // See the License for the specific language governing permissions and // limitations under the License. - #define LOG_TAG "vendor.eureka.hardware.flashlight@1.0-service" - + #include - + #include - + #include "Flashlight.h" - -using vendor::eureka::hardware::flashlight::V1_0::IFlashlight; -using vendor::eureka::hardware::flashlight::V1_0::Flashlight; + +using android::sp; using android::hardware::configureRpcThreadpool; using android::hardware::joinRpcThreadpool; -using android::sp; - +using vendor::eureka::hardware::flashlight::V1_0::Flashlight; +using vendor::eureka::hardware::flashlight::V1_0::IFlashlight; + int main() { - int ret; - android::sp service = Flashlight::getInstance(); - configureRpcThreadpool(1, true /*callerWillJoin*/); - - if (service != nullptr) { - ret = service->registerAsService(); - if(ret != 0) { - ALOGE("Can't register instance of Flashlight HAL, nullptr"); - }else{ - ALOGI("registered Flashlight HAL"); - } - } else { - ALOGE("Can't create instance of Flashlight HAL, nullptr"); - } - - joinRpcThreadpool(); - - return -1; // should never get here + int ret; + android::sp service = Flashlight::getInstance(); + configureRpcThreadpool(1, true /*callerWillJoin*/); + + if (service != nullptr) { + ret = service->registerAsService(); + if (ret != 0) { + ALOGE("Can't register instance of Flashlight HAL, nullptr"); + } else { + ALOGI("registered Flashlight HAL"); + } + } else { + ALOGE("Can't create instance of Flashlight HAL, nullptr"); + } + + joinRpcThreadpool(); + + return -1; // should never get here } diff --git a/universal7885-common/interfaces/hardware/gpu/1.0/default/Gpu.cpp b/universal7885-common/interfaces/hardware/gpu/1.0/default/Gpu.cpp index 657c881..6677f96 100644 --- a/universal7885-common/interfaces/hardware/gpu/1.0/default/Gpu.cpp +++ b/universal7885-common/interfaces/hardware/gpu/1.0/default/Gpu.cpp @@ -13,41 +13,41 @@ // limitations under the License. #include "Gpu.h" -#include #include +#include #include namespace vendor::eureka::hardware::gpu::V1_0 { Return Gpu::setGpuWritable(gpu::V1_0::Enable enable) { - std::ofstream file; - std::string writevalue; - if (enable == Enable::ENABLE){ + std::ofstream file; + std::string writevalue; + if (enable == Enable::ENABLE) { writevalue = "1"; - }else{ + } else { writevalue = "0"; - } - file.open("/sys/devices/platform/11500000.mali/tmu"); - file << writevalue; - file.close(); - return 0; + } + file.open("/sys/devices/platform/11500000.mali/tmu"); + file << writevalue; + file.close(); + return 0; } Return Gpu::readGpustats(void) { - std::ifstream file; - std::string value; - int32_t intvalue; - file.open("/sys/devices/platform/11500000.mali/tmu"); - if (file.is_open()) { - getline(file, value); - file.close(); - std::stringstream val(value); - val >> intvalue; - return intvalue; - } - return -1; + std::ifstream file; + std::string value; + int32_t intvalue; + file.open("/sys/devices/platform/11500000.mali/tmu"); + if (file.is_open()) { + getline(file, value); + file.close(); + std::stringstream val(value); + val >> intvalue; + return intvalue; + } + return -1; } -IGpu *Gpu::getInstance(void){ - return new Gpu(); +IGpu* Gpu::getInstance(void) { + return new Gpu(); } -} // namespace android::hardware::gpu::implementation +} // namespace vendor::eureka::hardware::gpu::V1_0 diff --git a/universal7885-common/interfaces/hardware/gpu/1.0/default/Gpu.h b/universal7885-common/interfaces/hardware/gpu/1.0/default/Gpu.h index 4ad1d14..3635602 100644 --- a/universal7885-common/interfaces/hardware/gpu/1.0/default/Gpu.h +++ b/universal7885-common/interfaces/hardware/gpu/1.0/default/Gpu.h @@ -14,19 +14,19 @@ #pragma once -#include #include #include +#include namespace vendor::eureka::hardware::gpu::V1_0 { +using ::android::sp; using ::android::hardware::hidl_array; using ::android::hardware::hidl_memory; using ::android::hardware::hidl_string; using ::android::hardware::hidl_vec; using ::android::hardware::Return; using ::android::hardware::Void; -using ::android::sp; struct Gpu : public IGpu { // Methods from ::vendor::eureka::hardware::gpu::V1_0::IGpu follow. @@ -34,6 +34,5 @@ struct Gpu : public IGpu { Return readGpustats(void); // Methods from ::android::hidl::base::V1_0::IBase follow. static IGpu* getInstance(void); - }; -} // namespace android::hardware::gpu::implementation +} // namespace vendor::eureka::hardware::gpu::V1_0 diff --git a/universal7885-common/interfaces/hardware/gpu/1.0/default/service.cpp b/universal7885-common/interfaces/hardware/gpu/1.0/default/service.cpp index 04316d5..b52e00c 100644 --- a/universal7885-common/interfaces/hardware/gpu/1.0/default/service.cpp +++ b/universal7885-common/interfaces/hardware/gpu/1.0/default/service.cpp @@ -12,38 +12,37 @@ // See the License for the specific language governing permissions and // limitations under the License. - #define LOG_TAG "vendor.eureka.hardware.gpu@1.0-service" - + #include - + #include - + #include "Gpu.h" - -using vendor::eureka::hardware::gpu::V1_0::IGpu; -using vendor::eureka::hardware::gpu::V1_0::Gpu; + +using android::sp; using android::hardware::configureRpcThreadpool; using android::hardware::joinRpcThreadpool; -using android::sp; - +using vendor::eureka::hardware::gpu::V1_0::Gpu; +using vendor::eureka::hardware::gpu::V1_0::IGpu; + int main() { - int ret; - android::sp service = Gpu::getInstance(); - configureRpcThreadpool(1, true /*callerWillJoin*/); - - if (service != nullptr) { - ret = service->registerAsService(); - if(ret != 0) { - ALOGE("Can't register instance of Gpu HAL, nullptr"); - }else{ - ALOGI("registered Gpu HAL"); - } - } else { - ALOGE("Can't create instance of Gpu HAL, nullptr"); - } - - joinRpcThreadpool(); - - return -1; // should never get here + int ret; + android::sp service = Gpu::getInstance(); + configureRpcThreadpool(1, true /*callerWillJoin*/); + + if (service != nullptr) { + ret = service->registerAsService(); + if (ret != 0) { + ALOGE("Can't register instance of Gpu HAL, nullptr"); + } else { + ALOGI("registered Gpu HAL"); + } + } else { + ALOGE("Can't create instance of Gpu HAL, nullptr"); + } + + joinRpcThreadpool(); + + return -1; // should never get here } diff --git a/universal7885-common/interfaces/security/selinux/1.0/default/SELinux.cpp b/universal7885-common/interfaces/security/selinux/1.0/default/SELinux.cpp index 019ef4c..a344d9e 100644 --- a/universal7885-common/interfaces/security/selinux/1.0/default/SELinux.cpp +++ b/universal7885-common/interfaces/security/selinux/1.0/default/SELinux.cpp @@ -13,41 +13,41 @@ // limitations under the License. #include "SELinux.h" -#include #include +#include #include namespace vendor::eureka::security::selinux::V1_0 { Return SELinux::setSELinuxWritable(selinux::V1_0::Enable enable) { - std::ofstream file; - std::string writevalue; - if (enable == Enable::ENABLE){ + std::ofstream file; + std::string writevalue; + if (enable == Enable::ENABLE) { writevalue = "1"; - }else{ + } else { writevalue = "0"; - } - file.open("/sys/fs/selinux/enforce"); - file << writevalue; - file.close(); - return 0; + } + file.open("/sys/fs/selinux/enforce"); + file << writevalue; + file.close(); + return 0; } Return SELinux::readSELinuxstats(void) { - std::ifstream file; - std::string value; - int32_t intvalue; - file.open("/sys/fs/selinux/enforce"); - if (file.is_open()) { - getline(file, value); - file.close(); - std::stringstream val(value); - val >> intvalue; - return intvalue; - } - return -1; + std::ifstream file; + std::string value; + int32_t intvalue; + file.open("/sys/fs/selinux/enforce"); + if (file.is_open()) { + getline(file, value); + file.close(); + std::stringstream val(value); + val >> intvalue; + return intvalue; + } + return -1; } -ISELinux *SELinux::getInstance(void){ - return new SELinux(); +ISELinux* SELinux::getInstance(void) { + return new SELinux(); } -} // namespace android::security::selinux::implementation +} // namespace vendor::eureka::security::selinux::V1_0 diff --git a/universal7885-common/interfaces/security/selinux/1.0/default/SELinux.h b/universal7885-common/interfaces/security/selinux/1.0/default/SELinux.h index d048773..0b2a44d 100644 --- a/universal7885-common/interfaces/security/selinux/1.0/default/SELinux.h +++ b/universal7885-common/interfaces/security/selinux/1.0/default/SELinux.h @@ -14,19 +14,19 @@ #pragma once -#include #include #include +#include namespace vendor::eureka::security::selinux::V1_0 { +using ::android::sp; using ::android::hardware::hidl_array; using ::android::hardware::hidl_memory; using ::android::hardware::hidl_string; using ::android::hardware::hidl_vec; using ::android::hardware::Return; using ::android::hardware::Void; -using ::android::sp; struct SELinux : public ISELinux { // Methods from ::vendor::eureka::security::selinux::V1_0::ISELinux follow. @@ -34,6 +34,5 @@ struct SELinux : public ISELinux { Return readSELinuxstats(void); // Methods from ::android::hidl::base::V1_0::IBase follow. static ISELinux* getInstance(void); - }; -} // namespace android::security::selinux::implementation +} // namespace vendor::eureka::security::selinux::V1_0 diff --git a/universal7885-common/interfaces/security/selinux/1.0/default/service.cpp b/universal7885-common/interfaces/security/selinux/1.0/default/service.cpp index a6f6a8c..c8db8eb 100644 --- a/universal7885-common/interfaces/security/selinux/1.0/default/service.cpp +++ b/universal7885-common/interfaces/security/selinux/1.0/default/service.cpp @@ -12,38 +12,37 @@ // See the License for the specific language governing permissions and // limitations under the License. - #define LOG_TAG "vendor.eureka.security.selinux@1.0-service" - + #include - + #include - + #include "SELinux.h" - -using vendor::eureka::security::selinux::V1_0::ISELinux; -using vendor::eureka::security::selinux::V1_0::SELinux; + +using android::sp; using android::hardware::configureRpcThreadpool; using android::hardware::joinRpcThreadpool; -using android::sp; - +using vendor::eureka::security::selinux::V1_0::ISELinux; +using vendor::eureka::security::selinux::V1_0::SELinux; + int main() { - int ret; - android::sp service = SELinux::getInstance(); - configureRpcThreadpool(1, true /*callerWillJoin*/); - - if (service != nullptr) { - ret = service->registerAsService(); - if(ret != 0) { - ALOGE("Can't register instance of SELinux HAL, nullptr"); - }else{ - ALOGI("registered SELinux HAL"); - } - } else { - ALOGE("Can't create instance of SELinux HAL, nullptr"); - } - - joinRpcThreadpool(); - - return -1; // should never get here + int ret; + android::sp service = SELinux::getInstance(); + configureRpcThreadpool(1, true /*callerWillJoin*/); + + if (service != nullptr) { + ret = service->registerAsService(); + if (ret != 0) { + ALOGE("Can't register instance of SELinux HAL, nullptr"); + } else { + ALOGI("registered SELinux HAL"); + } + } else { + ALOGE("Can't create instance of SELinux HAL, nullptr"); + } + + joinRpcThreadpool(); + + return -1; // should never get here } diff --git a/universal7885-common/libshims/camera/CameraMetadata.cpp b/universal7885-common/libshims/camera/CameraMetadata.cpp index 04bfbae..6827fbf 100644 --- a/universal7885-common/libshims/camera/CameraMetadata.cpp +++ b/universal7885-common/libshims/camera/CameraMetadata.cpp @@ -24,41 +24,34 @@ namespace android { -#define ALIGN_TO(val, alignment) \ - (((uintptr_t)(val) + ((alignment) - 1)) & ~((alignment) - 1)) +#define ALIGN_TO(val, alignment) (((uintptr_t)(val) + ((alignment)-1)) & ~((alignment)-1)) -CameraMetadata::CameraMetadata() : - mBuffer(NULL), mLocked(false) { -} +CameraMetadata::CameraMetadata() : mBuffer(NULL), mLocked(false) {} -CameraMetadata::CameraMetadata(size_t entryCapacity, size_t dataCapacity) : - mLocked(false) -{ +CameraMetadata::CameraMetadata(size_t entryCapacity, size_t dataCapacity) : mLocked(false) { mBuffer = allocate_camera_metadata(entryCapacity, dataCapacity); } -CameraMetadata::CameraMetadata(const CameraMetadata &other) : - mLocked(false) { +CameraMetadata::CameraMetadata(const CameraMetadata& other) : mLocked(false) { mBuffer = clone_camera_metadata(other.mBuffer); } -CameraMetadata::CameraMetadata(camera_metadata_t *buffer) : - mBuffer(NULL), mLocked(false) { +CameraMetadata::CameraMetadata(camera_metadata_t* buffer) : mBuffer(NULL), mLocked(false) { acquire(buffer); } -CameraMetadata &CameraMetadata::operator=(const CameraMetadata &other) { +CameraMetadata& CameraMetadata::operator=(const CameraMetadata& other) { return operator=(other.mBuffer); } -CameraMetadata &CameraMetadata::operator=(const camera_metadata_t *buffer) { +CameraMetadata& CameraMetadata::operator=(const camera_metadata_t* buffer) { if (mLocked) { ALOGE("%s: Assignment to a locked CameraMetadata!", __FUNCTION__); return *this; } if (CC_LIKELY(buffer != mBuffer)) { - camera_metadata_t *newBuffer = clone_camera_metadata(buffer); + camera_metadata_t* newBuffer = clone_camera_metadata(buffer); clear(); mBuffer = newBuffer; } @@ -75,14 +68,13 @@ const camera_metadata_t* CameraMetadata::getAndLock() const { return mBuffer; } -status_t CameraMetadata::unlock(const camera_metadata_t *buffer) const { +status_t CameraMetadata::unlock(const camera_metadata_t* buffer) const { if (!mLocked) { ALOGE("%s: Can't unlock a non-locked CameraMetadata!", __FUNCTION__); return INVALID_OPERATION; } if (buffer != mBuffer) { - ALOGE("%s: Can't unlock CameraMetadata with wrong pointer!", - __FUNCTION__); + ALOGE("%s: Can't unlock CameraMetadata with wrong pointer!", __FUNCTION__); return BAD_VALUE; } mLocked = false; @@ -94,7 +86,7 @@ camera_metadata_t* CameraMetadata::release() { ALOGE("%s: CameraMetadata is locked", __FUNCTION__); return NULL; } - camera_metadata_t *released = mBuffer; + camera_metadata_t* released = mBuffer; mBuffer = NULL; return released; } @@ -110,7 +102,7 @@ void CameraMetadata::clear() { } } -void CameraMetadata::acquire(camera_metadata_t *buffer) { +void CameraMetadata::acquire(camera_metadata_t* buffer) { if (mLocked) { ALOGE("%s: CameraMetadata is locked", __FUNCTION__); return; @@ -118,12 +110,11 @@ void CameraMetadata::acquire(camera_metadata_t *buffer) { clear(); mBuffer = buffer; - ALOGE_IF(validate_camera_metadata_structure(mBuffer, /*size*/NULL) != OK, - "%s: Failed to validate metadata structure %p", - __FUNCTION__, buffer); + ALOGE_IF(validate_camera_metadata_structure(mBuffer, /*size*/ NULL) != OK, + "%s: Failed to validate metadata structure %p", __FUNCTION__, buffer); } -void CameraMetadata::acquire(CameraMetadata &other) { +void CameraMetadata::acquire(CameraMetadata& other) { if (mLocked) { ALOGE("%s: CameraMetadata is locked", __FUNCTION__); return; @@ -131,7 +122,7 @@ void CameraMetadata::acquire(CameraMetadata &other) { acquire(other.release()); } -status_t CameraMetadata::append(const CameraMetadata &other) { +status_t CameraMetadata::append(const CameraMetadata& other) { return append(other.mBuffer); } @@ -148,8 +139,7 @@ status_t CameraMetadata::append(const camera_metadata_t* other) { } size_t CameraMetadata::entryCount() const { - return (mBuffer == NULL) ? 0 : - get_camera_metadata_entry_count(mBuffer); + return (mBuffer == NULL) ? 0 : get_camera_metadata_entry_count(mBuffer); } bool CameraMetadata::isEmpty() const { @@ -166,127 +156,119 @@ status_t CameraMetadata::sort() { status_t CameraMetadata::checkType(uint32_t tag, uint8_t expectedType) { int tagType = get_local_camera_metadata_tag_type(tag, mBuffer); - if ( CC_UNLIKELY(tagType == -1)) { + if (CC_UNLIKELY(tagType == -1)) { ALOGE("Update metadata entry: Unknown tag %d", tag); return INVALID_OPERATION; } - if ( CC_UNLIKELY(tagType != expectedType) ) { + if (CC_UNLIKELY(tagType != expectedType)) { ALOGE("Mismatched tag type when updating entry %s (%d) of type %s; " - "got type %s data instead ", - get_local_camera_metadata_tag_name(tag, mBuffer), tag, - camera_metadata_type_names[tagType], - camera_metadata_type_names[expectedType]); + "got type %s data instead ", + get_local_camera_metadata_tag_name(tag, mBuffer), tag, + camera_metadata_type_names[tagType], camera_metadata_type_names[expectedType]); return INVALID_OPERATION; } return OK; } -status_t CameraMetadata::update(uint32_t tag, - const int32_t *data, size_t data_count) { +status_t CameraMetadata::update(uint32_t tag, const int32_t* data, size_t data_count) { status_t res; if (mLocked) { ALOGE("%s: CameraMetadata is locked", __FUNCTION__); return INVALID_OPERATION; } - if ( (res = checkType(tag, TYPE_INT32)) != OK) { + if ((res = checkType(tag, TYPE_INT32)) != OK) { return res; } return updateImpl(tag, (const void*)data, data_count); } -status_t CameraMetadata::update(uint32_t tag, - const uint8_t *data, size_t data_count) { +status_t CameraMetadata::update(uint32_t tag, const uint8_t* data, size_t data_count) { status_t res; if (mLocked) { ALOGE("%s: CameraMetadata is locked", __FUNCTION__); return INVALID_OPERATION; } - if ( (res = checkType(tag, TYPE_BYTE)) != OK) { + if ((res = checkType(tag, TYPE_BYTE)) != OK) { return res; } return updateImpl(tag, (const void*)data, data_count); } -status_t CameraMetadata::update(uint32_t tag, - const float *data, size_t data_count) { +status_t CameraMetadata::update(uint32_t tag, const float* data, size_t data_count) { status_t res; if (mLocked) { ALOGE("%s: CameraMetadata is locked", __FUNCTION__); return INVALID_OPERATION; } - if ( (res = checkType(tag, TYPE_FLOAT)) != OK) { + if ((res = checkType(tag, TYPE_FLOAT)) != OK) { return res; } return updateImpl(tag, (const void*)data, data_count); } -status_t CameraMetadata::update(uint32_t tag, - const int64_t *data, size_t data_count) { +status_t CameraMetadata::update(uint32_t tag, const int64_t* data, size_t data_count) { status_t res; if (mLocked) { ALOGE("%s: CameraMetadata is locked", __FUNCTION__); return INVALID_OPERATION; } - if ( (res = checkType(tag, TYPE_INT64)) != OK) { + if ((res = checkType(tag, TYPE_INT64)) != OK) { return res; } return updateImpl(tag, (const void*)data, data_count); } -status_t CameraMetadata::update(uint32_t tag, - const double *data, size_t data_count) { +status_t CameraMetadata::update(uint32_t tag, const double* data, size_t data_count) { status_t res; if (mLocked) { ALOGE("%s: CameraMetadata is locked", __FUNCTION__); return INVALID_OPERATION; } - if ( (res = checkType(tag, TYPE_DOUBLE)) != OK) { + if ((res = checkType(tag, TYPE_DOUBLE)) != OK) { return res; } return updateImpl(tag, (const void*)data, data_count); } -status_t CameraMetadata::update(uint32_t tag, - const camera_metadata_rational_t *data, size_t data_count) { +status_t CameraMetadata::update(uint32_t tag, const camera_metadata_rational_t* data, + size_t data_count) { status_t res; if (mLocked) { ALOGE("%s: CameraMetadata is locked", __FUNCTION__); return INVALID_OPERATION; } - if ( (res = checkType(tag, TYPE_RATIONAL)) != OK) { + if ((res = checkType(tag, TYPE_RATIONAL)) != OK) { return res; } return updateImpl(tag, (const void*)data, data_count); } -status_t CameraMetadata::update(uint32_t tag, - const String8 &string) { +status_t CameraMetadata::update(uint32_t tag, const String8& string) { status_t res; if (mLocked) { ALOGE("%s: CameraMetadata is locked", __FUNCTION__); return INVALID_OPERATION; } - if ( (res = checkType(tag, TYPE_BYTE)) != OK) { + if ((res = checkType(tag, TYPE_BYTE)) != OK) { return res; } // string.size() doesn't count the null termination character. return updateImpl(tag, (const void*)string.string(), string.size() + 1); } -status_t CameraMetadata::update(const camera_metadata_ro_entry &entry) { +status_t CameraMetadata::update(const camera_metadata_ro_entry& entry) { status_t res; if (mLocked) { ALOGE("%s: CameraMetadata is locked", __FUNCTION__); return INVALID_OPERATION; } - if ( (res = checkType(entry.tag, entry.type)) != OK) { + if ((res = checkType(entry.tag, entry.type)) != OK) { return res; } return updateImpl(entry.tag, (const void*)entry.data.u8, entry.count); } -status_t CameraMetadata::updateImpl(uint32_t tag, const void *data, - size_t data_count) { +status_t CameraMetadata::updateImpl(uint32_t tag, const void* data, size_t data_count) { status_t res; if (mLocked) { ALOGE("%s: CameraMetadata is locked", __FUNCTION__); @@ -303,13 +285,11 @@ status_t CameraMetadata::updateImpl(uint32_t tag, const void *data, uintptr_t bufAddr = reinterpret_cast(mBuffer); uintptr_t dataAddr = reinterpret_cast(data); if (dataAddr > bufAddr && dataAddr < (bufAddr + bufferSize)) { - ALOGE("%s: Update attempted with data from the same metadata buffer!", - __FUNCTION__); + ALOGE("%s: Update attempted with data from the same metadata buffer!", __FUNCTION__); return INVALID_OPERATION; } - size_t data_size = calculate_camera_metadata_entry_data_size(type, - data_count); + size_t data_size = calculate_camera_metadata_entry_data_size(type, data_count); res = resizeIfNeeded(1, data_size); @@ -317,27 +297,23 @@ status_t CameraMetadata::updateImpl(uint32_t tag, const void *data, camera_metadata_entry_t entry; res = find_camera_metadata_entry(mBuffer, tag, &entry); if (res == NAME_NOT_FOUND) { - res = add_camera_metadata_entry(mBuffer, - tag, data, data_count); + res = add_camera_metadata_entry(mBuffer, tag, data, data_count); } else if (res == OK) { - res = update_camera_metadata_entry(mBuffer, - entry.index, data, data_count, NULL); + res = update_camera_metadata_entry(mBuffer, entry.index, data, data_count, NULL); } } if (res != OK) { - ALOGE("%s: Unable to update metadata entry %s.%s (%x): %s (%d)", - __FUNCTION__, get_local_camera_metadata_section_name(tag, mBuffer), - get_local_camera_metadata_tag_name(tag, mBuffer), tag, - strerror(-res), res); + ALOGE("%s: Unable to update metadata entry %s.%s (%x): %s (%d)", __FUNCTION__, + get_local_camera_metadata_section_name(tag, mBuffer), + get_local_camera_metadata_tag_name(tag, mBuffer), tag, strerror(-res), res); } IF_ALOGV() { - ALOGE_IF(validate_camera_metadata_structure(mBuffer, /*size*/NULL) != - OK, + ALOGE_IF(validate_camera_metadata_structure(mBuffer, /*size*/ NULL) != OK, - "%s: Failed to validate metadata structure after update %p", - __FUNCTION__, mBuffer); + "%s: Failed to validate metadata structure after update %p", __FUNCTION__, + mBuffer); } return res; @@ -357,7 +333,7 @@ camera_metadata_entry_t CameraMetadata::find(uint32_t tag) { return entry; } res = find_camera_metadata_entry(mBuffer, tag, &entry); - if (CC_UNLIKELY( res != OK )) { + if (CC_UNLIKELY(res != OK)) { entry.count = 0; entry.data.u8 = NULL; } @@ -368,7 +344,7 @@ camera_metadata_ro_entry_t CameraMetadata::find(uint32_t tag) const { status_t res; camera_metadata_ro_entry entry; res = find_camera_metadata_ro_entry(mBuffer, tag, &entry); - if (CC_UNLIKELY( res != OK )) { + if (CC_UNLIKELY(res != OK)) { entry.count = 0; entry.data.u8 = NULL; } @@ -386,20 +362,16 @@ status_t CameraMetadata::erase(uint32_t tag) { if (res == NAME_NOT_FOUND) { return OK; } else if (res != OK) { - ALOGE("%s: Error looking for entry %s.%s (%x): %s %d", - __FUNCTION__, - get_local_camera_metadata_section_name(tag, mBuffer), - get_local_camera_metadata_tag_name(tag, mBuffer), - tag, strerror(-res), res); + ALOGE("%s: Error looking for entry %s.%s (%x): %s %d", __FUNCTION__, + get_local_camera_metadata_section_name(tag, mBuffer), + get_local_camera_metadata_tag_name(tag, mBuffer), tag, strerror(-res), res); return res; } res = delete_camera_metadata_entry(mBuffer, entry.index); if (res != OK) { - ALOGE("%s: Error deleting entry %s.%s (%x): %s %d", - __FUNCTION__, - get_local_camera_metadata_section_name(tag, mBuffer), - get_local_camera_metadata_tag_name(tag, mBuffer), - tag, strerror(-res), res); + ALOGE("%s: Error deleting entry %s.%s (%x): %s %d", __FUNCTION__, + get_local_camera_metadata_section_name(tag, mBuffer), + get_local_camera_metadata_tag_name(tag, mBuffer), tag, strerror(-res), res); } return res; } @@ -418,23 +390,17 @@ status_t CameraMetadata::resizeIfNeeded(size_t extraEntries, size_t extraData) { } else { size_t currentEntryCount = get_camera_metadata_entry_count(mBuffer); size_t currentEntryCap = get_camera_metadata_entry_capacity(mBuffer); - size_t newEntryCount = currentEntryCount + - extraEntries; - newEntryCount = (newEntryCount > currentEntryCap) ? - newEntryCount * 2 : currentEntryCap; + size_t newEntryCount = currentEntryCount + extraEntries; + newEntryCount = (newEntryCount > currentEntryCap) ? newEntryCount * 2 : currentEntryCap; size_t currentDataCount = get_camera_metadata_data_count(mBuffer); size_t currentDataCap = get_camera_metadata_data_capacity(mBuffer); - size_t newDataCount = currentDataCount + - extraData; - newDataCount = (newDataCount > currentDataCap) ? - newDataCount * 2 : currentDataCap; + size_t newDataCount = currentDataCount + extraData; + newDataCount = (newDataCount > currentDataCap) ? newDataCount * 2 : currentDataCap; - if (newEntryCount > currentEntryCap || - newDataCount > currentDataCap) { - camera_metadata_t *oldBuffer = mBuffer; - mBuffer = allocate_camera_metadata(newEntryCount, - newDataCount); + if (newEntryCount > currentEntryCap || newDataCount > currentDataCap) { + camera_metadata_t* oldBuffer = mBuffer; + mBuffer = allocate_camera_metadata(newEntryCount, newDataCount); if (mBuffer == NULL) { ALOGE("%s: Can't allocate larger metadata buffer", __FUNCTION__); return NO_MEMORY; @@ -462,5 +428,4 @@ void CameraMetadata::swap(CameraMetadata& other) { mBuffer = otherBuf; } - -}; // namespace android +}; // namespace android diff --git a/universal7885-common/libshims/camera/CameraMetadata.h b/universal7885-common/libshims/camera/CameraMetadata.h index 6fe9383..5ba6f83 100644 --- a/universal7885-common/libshims/camera/CameraMetadata.h +++ b/universal7885-common/libshims/camera/CameraMetadata.h @@ -39,15 +39,15 @@ class CameraMetadata { ~CameraMetadata(); /** Takes ownership of passed-in buffer */ - CameraMetadata(camera_metadata_t *buffer); + CameraMetadata(camera_metadata_t* buffer); /** Clones the metadata */ - CameraMetadata(const CameraMetadata &other); + CameraMetadata(const CameraMetadata& other); /** * Assignment clones metadata buffer. */ - CameraMetadata &operator=(const CameraMetadata &other); - CameraMetadata &operator=(const camera_metadata_t *buffer); + CameraMetadata& operator=(const CameraMetadata& other); + CameraMetadata& operator=(const camera_metadata_t* buffer); /** * Get reference to the underlying metadata buffer. Ownership remains with @@ -64,7 +64,7 @@ class CameraMetadata { * from getAndLock must be provided to guarantee that the right object is * being unlocked. */ - status_t unlock(const camera_metadata_t *buffer) const; + status_t unlock(const camera_metadata_t* buffer) const; /** * Release a raw metadata buffer to the caller. After this call, @@ -91,12 +91,12 @@ class CameraMetadata { * Acquires raw buffer from other CameraMetadata object. After the call, the argument * object no longer has any metadata. */ - void acquire(CameraMetadata &other); + void acquire(CameraMetadata& other); /** * Append metadata from another CameraMetadata object. */ - status_t append(const CameraMetadata &other); + status_t append(const CameraMetadata& other); /** * Append metadata from a raw camera_metadata buffer @@ -123,24 +123,16 @@ class CameraMetadata { * will reallocate the buffer if insufficient space exists. Overloaded for * the various types of valid data. */ - status_t update(uint32_t tag, - const uint8_t *data, size_t data_count); - status_t update(uint32_t tag, - const int32_t *data, size_t data_count); - status_t update(uint32_t tag, - const float *data, size_t data_count); - status_t update(uint32_t tag, - const int64_t *data, size_t data_count); - status_t update(uint32_t tag, - const double *data, size_t data_count); - status_t update(uint32_t tag, - const camera_metadata_rational_t *data, size_t data_count); - status_t update(uint32_t tag, - const String8 &string); - status_t update(const camera_metadata_ro_entry &entry); + status_t update(uint32_t tag, const uint8_t* data, size_t data_count); + status_t update(uint32_t tag, const int32_t* data, size_t data_count); + status_t update(uint32_t tag, const float* data, size_t data_count); + status_t update(uint32_t tag, const int64_t* data, size_t data_count); + status_t update(uint32_t tag, const double* data, size_t data_count); + status_t update(uint32_t tag, const camera_metadata_rational_t* data, size_t data_count); + status_t update(uint32_t tag, const String8& string); + status_t update(const camera_metadata_ro_entry& entry); - - template + template status_t update(uint32_t tag, Vector data) { return update(tag, data.array(), data.size()); } @@ -170,7 +162,7 @@ class CameraMetadata { * Swap the underlying camera metadata between this and the other * metadata object. */ - void swap(CameraMetadata &other); + void swap(CameraMetadata& other); /** * Dump contents into FD for debugging. The verbosity levels are @@ -184,9 +176,9 @@ class CameraMetadata { void dump(int fd, int verbosity = 1, int indentation = 0) const; private: - camera_metadata_t *mBuffer; - volatile char mReserved[3] __attribute__ ((unused)); - mutable bool mLocked; + camera_metadata_t* mBuffer; + volatile char mReserved[3] __attribute__((unused)); + mutable bool mLocked; /** * Check if tag has a given type @@ -196,15 +188,14 @@ class CameraMetadata { /** * Base update entry method */ - status_t updateImpl(uint32_t tag, const void *data, size_t data_count); + status_t updateImpl(uint32_t tag, const void* data, size_t data_count); /** * Resize metadata buffer if needed by reallocating it and copying it over. */ status_t resizeIfNeeded(size_t extraEntries, size_t extraData); - }; -} // namespace android +} // namespace android #endif diff --git a/universal7885-common/libshims/camera/CameraParameters.cpp b/universal7885-common/libshims/camera/CameraParameters.cpp index 71f7c08..c0787b6 100644 --- a/universal7885-common/libshims/camera/CameraParameters.cpp +++ b/universal7885-common/libshims/camera/CameraParameters.cpp @@ -18,11 +18,11 @@ #define LOG_TAG "CameraParams" #include -#include #include +#include +#include #include #include "CameraParameters.h" -#include namespace android { @@ -74,7 +74,8 @@ const char CameraParameters::KEY_EXPOSURE_COMPENSATION_STEP[] = "exposure-compen const char CameraParameters::KEY_AUTO_EXPOSURE_LOCK[] = "auto-exposure-lock"; const char CameraParameters::KEY_AUTO_EXPOSURE_LOCK_SUPPORTED[] = "auto-exposure-lock-supported"; const char CameraParameters::KEY_AUTO_WHITEBALANCE_LOCK[] = "auto-whitebalance-lock"; -const char CameraParameters::KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED[] = "auto-whitebalance-lock-supported"; +const char CameraParameters::KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED[] = + "auto-whitebalance-lock-supported"; const char CameraParameters::KEY_MAX_NUM_METERING_AREAS[] = "max-num-metering-areas"; const char CameraParameters::KEY_METERING_AREAS[] = "metering-areas"; const char CameraParameters::KEY_ZOOM[] = "zoom"; @@ -86,7 +87,8 @@ const char CameraParameters::KEY_FOCUS_DISTANCES[] = "focus-distances"; const char CameraParameters::KEY_VIDEO_FRAME_FORMAT[] = "video-frame-format"; const char CameraParameters::KEY_VIDEO_SIZE[] = "video-size"; const char CameraParameters::KEY_SUPPORTED_VIDEO_SIZES[] = "video-size-values"; -const char CameraParameters::KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO[] = "preferred-preview-size-for-video"; +const char CameraParameters::KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO[] = + "preferred-preview-size-for-video"; const char CameraParameters::KEY_MAX_NUM_DETECTED_FACES_HW[] = "max-num-detected-faces-hw"; const char CameraParameters::KEY_MAX_NUM_DETECTED_FACES_SW[] = "max-num-detected-faces-sw"; const char CameraParameters::KEY_RECORDING_HINT[] = "recording-hint"; @@ -155,7 +157,7 @@ const char CameraParameters::SCENE_MODE_HDR[] = "hdr"; const char CameraParameters::PIXEL_FORMAT_YUV422SP[] = "yuv422sp"; const char CameraParameters::PIXEL_FORMAT_YUV420SP[] = "yuv420sp"; const char CameraParameters::PIXEL_FORMAT_YUV422I[] = "yuv422i-yuyv"; -const char CameraParameters::PIXEL_FORMAT_YUV420P[] = "yuv420p"; +const char CameraParameters::PIXEL_FORMAT_YUV420P[] = "yuv420p"; const char CameraParameters::PIXEL_FORMAT_RGB565[] = "rgb565"; const char CameraParameters::PIXEL_FORMAT_RGBA8888[] = "rgba8888"; const char CameraParameters::PIXEL_FORMAT_JPEG[] = "jpeg"; @@ -175,17 +177,11 @@ const char CameraParameters::FOCUS_MODE_CONTINUOUS_PICTURE[] = "continuous-pictu const char CameraParameters::LIGHTFX_LOWLIGHT[] = "low-light"; const char CameraParameters::LIGHTFX_HDR[] = "high-dynamic-range"; -CameraParameters::CameraParameters() - : mMap() -{ -} +CameraParameters::CameraParameters() : mMap() {} -CameraParameters::~CameraParameters() -{ -} +CameraParameters::~CameraParameters() {} -String8 CameraParameters::flatten() const -{ +String8 CameraParameters::flatten() const { String8 flattened(""); size_t size = mMap.size(); @@ -197,31 +193,28 @@ String8 CameraParameters::flatten() const flattened += k; flattened += "="; flattened += v; - if (i != size-1) - flattened += ";"; + if (i != size - 1) flattened += ";"; } return flattened; } -void CameraParameters::unflatten(const String8 ¶ms) -{ - const char *a = params.string(); - const char *b; +void CameraParameters::unflatten(const String8& params) { + const char* a = params.string(); + const char* b; mMap.clear(); for (;;) { // Find the bounds of the key name. b = strchr(a, '='); - if (b == 0) - break; + if (b == 0) break; // Create the key string. - String8 k(a, (size_t)(b-a)); + String8 k(a, (size_t)(b - a)); // Find the value. - a = b+1; + a = b + 1; b = strchr(a, ';'); if (b == 0) { // If there's no semicolon, this is the last item. @@ -230,15 +223,13 @@ void CameraParameters::unflatten(const String8 ¶ms) break; } - String8 v(a, (size_t)(b-a)); + String8 v(a, (size_t)(b - a)); mMap.add(k, v); - a = b+1; + a = b + 1; } } - -void CameraParameters::set(const char *key, const char *value) -{ +void CameraParameters::set(const char* key, const char* value) { // i think i can do this with strspn() if (strchr(key, '=') || strchr(key, ';')) { // ALOGE("Key \"%s\"contains invalid character (= or ;)", key); @@ -253,54 +244,44 @@ void CameraParameters::set(const char *key, const char *value) mMap.replaceValueFor(String8(key), String8(value)); } -void CameraParameters::set(const char *key, int value) -{ +void CameraParameters::set(const char* key, int value) { char str[16]; sprintf(str, "%d", value); set(key, str); } -void CameraParameters::setFloat(const char *key, float value) -{ +void CameraParameters::setFloat(const char* key, float value) { char str[16]; // 14 should be enough. We overestimate to be safe. snprintf(str, sizeof(str), "%g", value); set(key, str); } -const char *CameraParameters::get(const char *key) const -{ +const char* CameraParameters::get(const char* key) const { String8 v = mMap.valueFor(String8(key)); - if (v.length() == 0) - return 0; + if (v.length() == 0) return 0; return v.string(); } -int CameraParameters::getInt(const char *key) const -{ - const char *v = get(key); - if (v == 0) - return -1; +int CameraParameters::getInt(const char* key) const { + const char* v = get(key); + if (v == 0) return -1; return strtol(v, 0, 0); } -float CameraParameters::getFloat(const char *key) const -{ - const char *v = get(key); +float CameraParameters::getFloat(const char* key) const { + const char* v = get(key); if (v == 0) return -1; return strtof(v, 0); } -void CameraParameters::remove(const char *key) -{ +void CameraParameters::remove(const char* key) { mMap.removeItem(String8(key)); } // Parse string like "640x480" or "10000,20000" -static int parse_pair(const char *str, int *first, int *second, char delim, - char **endptr = NULL) -{ +static int parse_pair(const char* str, int* first, int* second, char delim, char** endptr = NULL) { // Find the first integer. - char *end; + char* end; int w = (int)strtol(str, &end, 10); // If a delimeter does not immediately follow, give up. if (*end != delim) { @@ -309,7 +290,7 @@ static int parse_pair(const char *str, int *first, int *second, char delim, } // Find the second integer, immediately after the delimeter. - int h = (int)strtol(end+1, &end, 10); + int h = (int)strtol(end + 1, &end, 10); *first = w; *second = h; @@ -321,18 +302,16 @@ static int parse_pair(const char *str, int *first, int *second, char delim, return 0; } -static void parseSizesList(const char *sizesStr, Vector &sizes) -{ +static void parseSizesList(const char* sizesStr, Vector& sizes) { if (sizesStr == 0) { return; } - char *sizeStartPtr = (char *)sizesStr; + char* sizeStartPtr = (char*)sizesStr; while (true) { int width, height; - int success = parse_pair(sizeStartPtr, &width, &height, 'x', - &sizeStartPtr); + int success = parse_pair(sizeStartPtr, &width, &height, 'x', &sizeStartPtr); if (success == -1 || (*sizeStartPtr != ',' && *sizeStartPtr != '\0')) { ALOGE("Picture sizes string \"%s\" contains invalid character.", sizesStr); return; @@ -346,119 +325,101 @@ static void parseSizesList(const char *sizesStr, Vector &sizes) } } -void CameraParameters::setPreviewSize(int width, int height) -{ +void CameraParameters::setPreviewSize(int width, int height) { char str[32]; sprintf(str, "%dx%d", width, height); set(KEY_PREVIEW_SIZE, str); } -void CameraParameters::getPreviewSize(int *width, int *height) const -{ +void CameraParameters::getPreviewSize(int* width, int* height) const { *width = *height = -1; // Get the current string, if it doesn't exist, leave the -1x-1 - const char *p = get(KEY_PREVIEW_SIZE); - if (p == 0) return; + const char* p = get(KEY_PREVIEW_SIZE); + if (p == 0) return; parse_pair(p, width, height, 'x'); } -void CameraParameters::getPreferredPreviewSizeForVideo(int *width, int *height) const -{ +void CameraParameters::getPreferredPreviewSizeForVideo(int* width, int* height) const { *width = *height = -1; - const char *p = get(KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO); - if (p == 0) return; + const char* p = get(KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO); + if (p == 0) return; parse_pair(p, width, height, 'x'); } -void CameraParameters::getSupportedPreviewSizes(Vector &sizes) const -{ - const char *previewSizesStr = get(KEY_SUPPORTED_PREVIEW_SIZES); +void CameraParameters::getSupportedPreviewSizes(Vector& sizes) const { + const char* previewSizesStr = get(KEY_SUPPORTED_PREVIEW_SIZES); parseSizesList(previewSizesStr, sizes); } -void CameraParameters::setVideoSize(int width, int height) -{ +void CameraParameters::setVideoSize(int width, int height) { char str[32]; sprintf(str, "%dx%d", width, height); set(KEY_VIDEO_SIZE, str); } -void CameraParameters::getVideoSize(int *width, int *height) const -{ +void CameraParameters::getVideoSize(int* width, int* height) const { *width = *height = -1; - const char *p = get(KEY_VIDEO_SIZE); + const char* p = get(KEY_VIDEO_SIZE); if (p == 0) return; parse_pair(p, width, height, 'x'); } -void CameraParameters::getSupportedVideoSizes(Vector &sizes) const -{ - const char *videoSizesStr = get(KEY_SUPPORTED_VIDEO_SIZES); +void CameraParameters::getSupportedVideoSizes(Vector& sizes) const { + const char* videoSizesStr = get(KEY_SUPPORTED_VIDEO_SIZES); parseSizesList(videoSizesStr, sizes); } -void CameraParameters::setPreviewFrameRate(int fps) -{ +void CameraParameters::setPreviewFrameRate(int fps) { set(KEY_PREVIEW_FRAME_RATE, fps); } -int CameraParameters::getPreviewFrameRate() const -{ +int CameraParameters::getPreviewFrameRate() const { return getInt(KEY_PREVIEW_FRAME_RATE); } -void CameraParameters::getPreviewFpsRange(int *min_fps, int *max_fps) const -{ +void CameraParameters::getPreviewFpsRange(int* min_fps, int* max_fps) const { *min_fps = *max_fps = -1; - const char *p = get(KEY_PREVIEW_FPS_RANGE); + const char* p = get(KEY_PREVIEW_FPS_RANGE); if (p == 0) return; parse_pair(p, min_fps, max_fps, ','); } -void CameraParameters::setPreviewFormat(const char *format) -{ +void CameraParameters::setPreviewFormat(const char* format) { set(KEY_PREVIEW_FORMAT, format); } -const char *CameraParameters::getPreviewFormat() const -{ +const char* CameraParameters::getPreviewFormat() const { return get(KEY_PREVIEW_FORMAT); } -void CameraParameters::setPictureSize(int width, int height) -{ +void CameraParameters::setPictureSize(int width, int height) { char str[32]; sprintf(str, "%dx%d", width, height); set(KEY_PICTURE_SIZE, str); } -void CameraParameters::getPictureSize(int *width, int *height) const -{ +void CameraParameters::getPictureSize(int* width, int* height) const { *width = *height = -1; // Get the current string, if it doesn't exist, leave the -1x-1 - const char *p = get(KEY_PICTURE_SIZE); + const char* p = get(KEY_PICTURE_SIZE); if (p == 0) return; parse_pair(p, width, height, 'x'); } -void CameraParameters::getSupportedPictureSizes(Vector &sizes) const -{ - const char *pictureSizesStr = get(KEY_SUPPORTED_PICTURE_SIZES); +void CameraParameters::getSupportedPictureSizes(Vector& sizes) const { + const char* pictureSizesStr = get(KEY_SUPPORTED_PICTURE_SIZES); parseSizesList(pictureSizesStr, sizes); } -void CameraParameters::setPictureFormat(const char *format) -{ +void CameraParameters::setPictureFormat(const char* format) { set(KEY_PICTURE_FORMAT, format); } -const char *CameraParameters::getPictureFormat() const -{ +const char* CameraParameters::getPictureFormat() const { return get(KEY_PICTURE_FORMAT); } -void CameraParameters::dump() const -{ +void CameraParameters::dump() const { ALOGD("dump: mMap.size = %zu", mMap.size()); for (size_t i = 0; i < mMap.size(); i++) { String8 k, v; @@ -468,8 +429,7 @@ void CameraParameters::dump() const } } -status_t CameraParameters::dump(int fd, const Vector& /*args*/) const -{ +status_t CameraParameters::dump(int fd, const Vector& /*args*/) const { const size_t SIZE = 256; char buffer[SIZE]; String8 result; @@ -487,8 +447,7 @@ status_t CameraParameters::dump(int fd, const Vector& /*args*/) const } void CameraParameters::getSupportedPreviewFormats(Vector& formats) const { - const char* supportedPreviewFormats = - get(CameraParameters::KEY_SUPPORTED_PREVIEW_FORMATS); + const char* supportedPreviewFormats = get(CameraParameters::KEY_SUPPORTED_PREVIEW_FORMATS); if (supportedPreviewFormats == NULL) { ALOGW("%s: No supported preview formats.", __FUNCTION__); @@ -510,30 +469,27 @@ void CameraParameters::getSupportedPreviewFormats(Vector& formats) const { fmtStr.unlockBuffer(fmtStr.size()); } - int CameraParameters::previewFormatToEnum(const char* format) { - return - !format ? - HAL_PIXEL_FORMAT_YCrCb_420_SP : - !strcmp(format, PIXEL_FORMAT_YUV422SP) ? - HAL_PIXEL_FORMAT_YCbCr_422_SP : // NV16 - !strcmp(format, PIXEL_FORMAT_YUV420SP) ? - HAL_PIXEL_FORMAT_YCrCb_420_SP : // NV21 - !strcmp(format, PIXEL_FORMAT_YUV422I) ? - HAL_PIXEL_FORMAT_YCbCr_422_I : // YUY2 - !strcmp(format, PIXEL_FORMAT_YUV420P) ? - HAL_PIXEL_FORMAT_YV12 : // YV12 - !strcmp(format, PIXEL_FORMAT_RGB565) ? - HAL_PIXEL_FORMAT_RGB_565 : // RGB565 - !strcmp(format, PIXEL_FORMAT_RGBA8888) ? - HAL_PIXEL_FORMAT_RGBA_8888 : // RGB8888 - !strcmp(format, PIXEL_FORMAT_BAYER_RGGB) ? - HAL_PIXEL_FORMAT_RAW16 : // Raw sensor data - -1; + return !format ? HAL_PIXEL_FORMAT_YCrCb_420_SP + : !strcmp(format, PIXEL_FORMAT_YUV422SP) ? HAL_PIXEL_FORMAT_YCbCr_422_SP + : // NV16 + !strcmp(format, PIXEL_FORMAT_YUV420SP) ? HAL_PIXEL_FORMAT_YCrCb_420_SP + : // NV21 + !strcmp(format, PIXEL_FORMAT_YUV422I) ? HAL_PIXEL_FORMAT_YCbCr_422_I + : // YUY2 + !strcmp(format, PIXEL_FORMAT_YUV420P) ? HAL_PIXEL_FORMAT_YV12 + : // YV12 + !strcmp(format, PIXEL_FORMAT_RGB565) ? HAL_PIXEL_FORMAT_RGB_565 + : // RGB565 + !strcmp(format, PIXEL_FORMAT_RGBA8888) ? HAL_PIXEL_FORMAT_RGBA_8888 + : // RGB8888 + !strcmp(format, PIXEL_FORMAT_BAYER_RGGB) ? HAL_PIXEL_FORMAT_RAW16 + : // Raw sensor data + -1; } bool CameraParameters::isEmpty() const { return mMap.isEmpty(); } -}; // namespace android +}; // namespace android diff --git a/universal7885-common/libshims/camera/CameraParameters.h b/universal7885-common/libshims/camera/CameraParameters.h index 7af3b99..1e064c8 100644 --- a/universal7885-common/libshims/camera/CameraParameters.h +++ b/universal7885-common/libshims/camera/CameraParameters.h @@ -37,28 +37,27 @@ struct Size { } }; -class CameraParameters -{ -public: +class CameraParameters { + public: CameraParameters(); - CameraParameters(const String8 ¶ms) { unflatten(params); } + CameraParameters(const String8& params) { unflatten(params); } ~CameraParameters(); String8 flatten() const; - void unflatten(const String8 ¶ms); + void unflatten(const String8& params); - void set(const char *key, const char *value); - void set(const char *key, int value); - void setFloat(const char *key, float value); - const char *get(const char *key) const; - int getInt(const char *key) const; - float getFloat(const char *key) const; + void set(const char* key, const char* value); + void set(const char* key, int value); + void setFloat(const char* key, float value); + const char* get(const char* key) const; + int getInt(const char* key) const; + float getFloat(const char* key) const; - void remove(const char *key); + void remove(const char* key); void setPreviewSize(int width, int height); - void getPreviewSize(int *width, int *height) const; - void getSupportedPreviewSizes(Vector &sizes) const; + void getPreviewSize(int* width, int* height) const; + void getSupportedPreviewSizes(Vector& sizes) const; // Set the dimensions in pixels to the given width and height // for video frames. The given width and height must be one @@ -71,14 +70,14 @@ public: // supported dimensions returned from getSupportedVideoSizes(). // Must not be called if getSupportedVideoSizes() returns an // empty Vector of Size. - void getVideoSize(int *width, int *height) const; + void getVideoSize(int* width, int* height) const; // Retrieve a Vector of supported dimensions (width and height) // in pixels for video frames. If sizes returned from the method // is empty, the camera does not support calls to setVideoSize() // or getVideoSize(). In adddition, it also indicates that // the camera only has a single output, and does not have // separate output for video frames and preview frame. - void getSupportedVideoSizes(Vector &sizes) const; + void getSupportedVideoSizes(Vector& sizes) const; // Retrieve the preferred preview size (width and height) in pixels // for video recording. The given width and height must be one of // supported preview sizes returned from getSupportedPreviewSizes(). @@ -86,18 +85,18 @@ public: // Vector of Size. If getSupportedVideoSizes() returns an empty // Vector of Size, the width and height returned from this method // is invalid, and is "-1x-1". - void getPreferredPreviewSizeForVideo(int *width, int *height) const; + void getPreferredPreviewSizeForVideo(int* width, int* height) const; void setPreviewFrameRate(int fps); int getPreviewFrameRate() const; - void getPreviewFpsRange(int *min_fps, int *max_fps) const; - void setPreviewFormat(const char *format); - const char *getPreviewFormat() const; + void getPreviewFpsRange(int* min_fps, int* max_fps) const; + void setPreviewFormat(const char* format); + const char* getPreviewFormat() const; void setPictureSize(int width, int height); - void getPictureSize(int *width, int *height) const; - void getSupportedPictureSizes(Vector &sizes) const; - void setPictureFormat(const char *format); - const char *getPictureFormat() const; + void getPictureSize(int* width, int* height) const; + void getSupportedPictureSizes(Vector& sizes) const; + void setPictureFormat(const char* format); + const char* getPictureFormat() const; void dump() const; status_t dump(int fd, const Vector& args) const; @@ -614,9 +613,9 @@ public: // Pixel color formats for KEY_PREVIEW_FORMAT, KEY_PICTURE_FORMAT, // and KEY_VIDEO_FRAME_FORMAT static const char PIXEL_FORMAT_YUV422SP[]; - static const char PIXEL_FORMAT_YUV420SP[]; // NV21 - static const char PIXEL_FORMAT_YUV422I[]; // YUY2 - static const char PIXEL_FORMAT_YUV420P[]; // YV12 + static const char PIXEL_FORMAT_YUV420SP[]; // NV21 + static const char PIXEL_FORMAT_YUV422I[]; // YUY2 + static const char PIXEL_FORMAT_YUV420P[]; // YV12 static const char PIXEL_FORMAT_RGB565[]; static const char PIXEL_FORMAT_RGBA8888[]; static const char PIXEL_FORMAT_JPEG[]; @@ -690,10 +689,10 @@ public: */ static int previewFormatToEnum(const char* format); -private: - DefaultKeyedVector mMap; + private: + DefaultKeyedVector mMap; }; -}; // namespace +}; // namespace android #endif diff --git a/universal7885-common/libshims/sensor/ASensorManager.cpp b/universal7885-common/libshims/sensor/ASensorManager.cpp index 0d059e6..2a645c4 100644 --- a/universal7885-common/libshims/sensor/ASensorManager.cpp +++ b/universal7885-common/libshims/sensor/ASensorManager.cpp @@ -23,9 +23,9 @@ using android::Mutex; static Mutex gLock; -extern "C" ALooper *ALooper_forCamera() { +extern "C" ALooper* ALooper_forCamera() { LOG(VERBOSE) << "ALooper_forCamera"; - ALooper *sLooper = NULL; + ALooper* sLooper = NULL; Mutex::Autolock autoLock(gLock); sLooper = new ALooper; @@ -33,7 +33,7 @@ extern "C" ALooper *ALooper_forCamera() { return sLooper; } -extern "C" int ALooper_release_forCamera(ALooper *sLooper) { +extern "C" int ALooper_release_forCamera(ALooper* sLooper) { if (sLooper != nullptr) { Mutex::Autolock autoLock(gLock); delete sLooper; @@ -42,11 +42,8 @@ extern "C" int ALooper_release_forCamera(ALooper *sLooper) { return 0; } -extern "C" int ALooper_pollOnce_camera(ALooper *sLooper, - int timeoutMillis, - int* outFd, - int* outEvents, - void** outData) { +extern "C" int ALooper_pollOnce_camera(ALooper* sLooper, int timeoutMillis, int* outFd, + int* outEvents, void** outData) { int res = sLooper->pollOnce(timeoutMillis, outFd, outEvents, outData); LOG(VERBOSE) << "ALooper_pollOnce_camera => " << res; return res; diff --git a/universal7885-common/secril_config_svc/secril_config_svc.cpp b/universal7885-common/secril_config_svc/secril_config_svc.cpp index cc49804..86eb933 100644 --- a/universal7885-common/secril_config_svc/secril_config_svc.cpp +++ b/universal7885-common/secril_config_svc/secril_config_svc.cpp @@ -42,11 +42,10 @@ void LoadProperties(std::string data) { } } -int main(int argc, char *argv[]) { +int main(int argc, char* argv[]) { std::string prop = FACTORY_PROP; - if (argc > 1 && std::string(argv[1]) == "NetworkConfig") - prop = TELEPHONY_PROP; + if (argc > 1 && std::string(argv[1]) == "NetworkConfig") prop = TELEPHONY_PROP; std::ifstream in(EFS_NEW + prop); if (in.good()) { diff --git a/universal7885-common/usb/typeb/Usb.cpp b/universal7885-common/usb/typeb/Usb.cpp old mode 100755 new mode 100644 index f42452f..17775f2 --- a/universal7885-common/usb/typeb/Usb.cpp +++ b/universal7885-common/usb/typeb/Usb.cpp @@ -30,8 +30,8 @@ namespace usb { namespace V1_0 { namespace implementation { -Return Usb::switchRole(const hidl_string &portName __unused, - const PortRole &newRole __unused) { +Return Usb::switchRole(const hidl_string& portName __unused, + const PortRole& newRole __unused) { LOG(ERROR) << __func__ << ": Not supported"; return Void(); } @@ -51,8 +51,7 @@ Return Usb::queryPortStatus() { pthread_mutex_lock(&mLock); if (mCallback != NULL) { - Return ret = - mCallback->notifyPortStatusChange(currentPortStatus, Status::SUCCESS); + Return ret = mCallback->notifyPortStatusChange(currentPortStatus, Status::SUCCESS); if (!ret.isOk()) { LOG(ERROR) << "queryPortStatus error " << ret.description(); } @@ -64,7 +63,7 @@ Return Usb::queryPortStatus() { return Void(); } -Return Usb::setCallback(const sp &callback) { +Return Usb::setCallback(const sp& callback) { pthread_mutex_lock(&mLock); mCallback = callback; diff --git a/universal7885-common/usb/typeb/Usb.h b/universal7885-common/usb/typeb/Usb.h old mode 100755 new mode 100644 index 5517f80..16874c5 --- a/universal7885-common/usb/typeb/Usb.h +++ b/universal7885-common/usb/typeb/Usb.h @@ -35,17 +35,17 @@ namespace usb { namespace V1_0 { namespace implementation { -using ::android::hardware::usb::V1_0::IUsb; -using ::android::hardware::usb::V1_0::IUsbCallback; -using ::android::hardware::usb::V1_0::PortRole; -using ::android::hidl::base::V1_0::IBase; +using ::android::sp; using ::android::hardware::hidl_array; using ::android::hardware::hidl_memory; using ::android::hardware::hidl_string; using ::android::hardware::hidl_vec; using ::android::hardware::Return; using ::android::hardware::Void; -using ::android::sp; +using ::android::hardware::usb::V1_0::IUsb; +using ::android::hardware::usb::V1_0::IUsbCallback; +using ::android::hardware::usb::V1_0::PortRole; +using ::android::hidl::base::V1_0::IBase; struct Usb : public IUsb { Return switchRole(const hidl_string& portName, const PortRole& role) override; diff --git a/universal7885-common/usb/typec/Usb.cpp b/universal7885-common/usb/typec/Usb.cpp index 1ff26d2..d68b57b 100644 --- a/universal7885-common/usb/typec/Usb.cpp +++ b/universal7885-common/usb/typec/Usb.cpp @@ -18,14 +18,14 @@ #include #include -#include #include #include -#include #include #include -#include #include +#include +#include +#include #include #include @@ -49,174 +49,166 @@ volatile bool destroyThread; static void checkUsbDeviceAutoSuspend(const std::string& devicePath); -static int32_t readFile(const std::string &filename, std::string *contents) { - FILE *fp; - ssize_t read = 0; - char *line = NULL; - size_t len = 0; +static int32_t readFile(const std::string& filename, std::string* contents) { + FILE* fp; + ssize_t read = 0; + char* line = NULL; + size_t len = 0; - fp = fopen(filename.c_str(), "r"); - if (fp != NULL) { - if ((read = getline(&line, &len, fp)) != -1) { - char *pos; - if ((pos = strchr(line, '\n')) != NULL) *pos = '\0'; - *contents = line; + fp = fopen(filename.c_str(), "r"); + if (fp != NULL) { + if ((read = getline(&line, &len, fp)) != -1) { + char* pos; + if ((pos = strchr(line, '\n')) != NULL) *pos = '\0'; + *contents = line; + } + free(line); + fclose(fp); + return 0; + } else { + ALOGE("fopen failed in readFile %s, errno=%d", filename.c_str(), errno); } - free(line); - fclose(fp); - return 0; - } else { - ALOGE("fopen failed in readFile %s, errno=%d", filename.c_str(), errno); - } - return -1; + return -1; } -static int32_t writeFile(const std::string &filename, - const std::string &contents) { - FILE *fp; - int ret; +static int32_t writeFile(const std::string& filename, const std::string& contents) { + FILE* fp; + int ret; - fp = fopen(filename.c_str(), "w"); - if (fp != NULL) { - ret = fputs(contents.c_str(), fp); - fclose(fp); - if (ret == EOF) { - ALOGE("fputs failed in writeFile %s", filename.c_str()); - return -1; + fp = fopen(filename.c_str(), "w"); + if (fp != NULL) { + ret = fputs(contents.c_str(), fp); + fclose(fp); + if (ret == EOF) { + ALOGE("fputs failed in writeFile %s", filename.c_str()); + return -1; + } + return 0; + } else { + ALOGE("fopen failed in writeFile %s, errno=%d", filename.c_str(), errno); } - return 0; - } else { - ALOGE("fopen failed in writeFile %s, errno=%d", filename.c_str(), errno); - } - return -1; + return -1; } -std::string appendRoleNodeHelper(const std::string &portName, - PortRoleType type) { - std::string node("/sys/class/typec/" + portName); +std::string appendRoleNodeHelper(const std::string& portName, PortRoleType type) { + std::string node("/sys/class/typec/" + portName); - switch (type) { - case PortRoleType::DATA_ROLE: - return node + "/data_role"; - case PortRoleType::POWER_ROLE: - return node + "/power_role"; - case PortRoleType::MODE: - return node + "/port_type"; - default: - return ""; - } + switch (type) { + case PortRoleType::DATA_ROLE: + return node + "/data_role"; + case PortRoleType::POWER_ROLE: + return node + "/power_role"; + case PortRoleType::MODE: + return node + "/port_type"; + default: + return ""; + } } std::string convertRoletoString(PortRole role) { - if (role.type == PortRoleType::POWER_ROLE) { - if (role.role == static_cast(PortPowerRole::SOURCE)) - return "source"; - else if (role.role == static_cast(PortPowerRole::SINK)) - return "sink"; - } else if (role.type == PortRoleType::DATA_ROLE) { - if (role.role == static_cast(PortDataRole::HOST)) return "host"; - if (role.role == static_cast(PortDataRole::DEVICE)) - return "device"; - } else if (role.type == PortRoleType::MODE) { - if (role.role == static_cast(PortMode_1_1::UFP)) return "sink"; - if (role.role == static_cast(PortMode_1_1::DFP)) return "source"; - } - return "none"; + if (role.type == PortRoleType::POWER_ROLE) { + if (role.role == static_cast(PortPowerRole::SOURCE)) + return "source"; + else if (role.role == static_cast(PortPowerRole::SINK)) + return "sink"; + } else if (role.type == PortRoleType::DATA_ROLE) { + if (role.role == static_cast(PortDataRole::HOST)) return "host"; + if (role.role == static_cast(PortDataRole::DEVICE)) return "device"; + } else if (role.type == PortRoleType::MODE) { + if (role.role == static_cast(PortMode_1_1::UFP)) return "sink"; + if (role.role == static_cast(PortMode_1_1::DFP)) return "source"; + } + return "none"; } -void extractRole(std::string *roleName) { - std::size_t first, last; +void extractRole(std::string* roleName) { + std::size_t first, last; - first = roleName->find("["); - last = roleName->find("]"); + first = roleName->find("["); + last = roleName->find("]"); - if (first != std::string::npos && last != std::string::npos) { - *roleName = roleName->substr(first + 1, last - first - 1); - } + if (first != std::string::npos && last != std::string::npos) { + *roleName = roleName->substr(first + 1, last - first - 1); + } } -void switchToDrp(const std::string &portName) { - std::string filename = - appendRoleNodeHelper(std::string(portName.c_str()), PortRoleType::MODE); - FILE *fp; +void switchToDrp(const std::string& portName) { + std::string filename = appendRoleNodeHelper(std::string(portName.c_str()), PortRoleType::MODE); + FILE* fp; + + if (filename != "") { + fp = fopen(filename.c_str(), "w"); + if (fp != NULL) { + int ret = fputs("dual", fp); + fclose(fp); + if (ret == EOF) ALOGE("Fatal: Error while switching back to drp"); + } else { + ALOGE("Fatal: Cannot open file to switch back to drp"); + } + } else { + ALOGE("Fatal: invalid node type"); + } +} + +bool switchMode(const hidl_string& portName, const PortRole& newRole, struct Usb* usb) { + std::string filename = appendRoleNodeHelper(std::string(portName.c_str()), newRole.type); + std::string written; + FILE* fp; + bool roleSwitch = false; + + if (filename == "") { + ALOGE("Fatal: invalid node type"); + return false; + } - if (filename != "") { fp = fopen(filename.c_str(), "w"); if (fp != NULL) { - int ret = fputs("dual", fp); - fclose(fp); - if (ret == EOF) - ALOGE("Fatal: Error while switching back to drp"); - } else { - ALOGE("Fatal: Cannot open file to switch back to drp"); + // Hold the lock here to prevent loosing connected signals + // as once the file is written the partner added signal + // can arrive anytime. + pthread_mutex_lock(&usb->mPartnerLock); + usb->mPartnerUp = false; + int ret = fputs(convertRoletoString(newRole).c_str(), fp); + fclose(fp); + + if (ret != EOF) { + struct timespec to; + struct timespec now; + + wait_again: + clock_gettime(CLOCK_MONOTONIC, &now); + to.tv_sec = now.tv_sec + PORT_TYPE_TIMEOUT; + to.tv_nsec = now.tv_nsec; + + int err = pthread_cond_timedwait(&usb->mPartnerCV, &usb->mPartnerLock, &to); + // There are no uevent signals which implies role swap timed out. + if (err == ETIMEDOUT) { + ALOGI("uevents wait timedout"); + // Sanity check. + } else if (!usb->mPartnerUp) { + goto wait_again; + // Role switch succeeded since usb->mPartnerUp is true. + } else { + roleSwitch = true; + } + } else { + ALOGI("Role switch failed while wrting to file"); + } + pthread_mutex_unlock(&usb->mPartnerLock); } - } else { - ALOGE("Fatal: invalid node type"); - } -} -bool switchMode(const hidl_string &portName, - const PortRole &newRole, struct Usb *usb) { - std::string filename = - appendRoleNodeHelper(std::string(portName.c_str()), newRole.type); - std::string written; - FILE *fp; - bool roleSwitch = false; + if (!roleSwitch) switchToDrp(std::string(portName.c_str())); - if (filename == "") { - ALOGE("Fatal: invalid node type"); - return false; - } - - fp = fopen(filename.c_str(), "w"); - if (fp != NULL) { - // Hold the lock here to prevent loosing connected signals - // as once the file is written the partner added signal - // can arrive anytime. - pthread_mutex_lock(&usb->mPartnerLock); - usb->mPartnerUp = false; - int ret = fputs(convertRoletoString(newRole).c_str(), fp); - fclose(fp); - - if (ret != EOF) { - struct timespec to; - struct timespec now; - -wait_again: - clock_gettime(CLOCK_MONOTONIC, &now); - to.tv_sec = now.tv_sec + PORT_TYPE_TIMEOUT; - to.tv_nsec = now.tv_nsec; - - int err = pthread_cond_timedwait(&usb->mPartnerCV, &usb->mPartnerLock, &to); - // There are no uevent signals which implies role swap timed out. - if (err == ETIMEDOUT) { - ALOGI("uevents wait timedout"); - // Sanity check. - } else if (!usb->mPartnerUp) { - goto wait_again; - // Role switch succeeded since usb->mPartnerUp is true. - } else { - roleSwitch = true; - } - } else { - ALOGI("Role switch failed while wrting to file"); - } - pthread_mutex_unlock(&usb->mPartnerLock); - } - - if (!roleSwitch) - switchToDrp(std::string(portName.c_str())); - - return roleSwitch; + return roleSwitch; } Usb::Usb() - : mLock(PTHREAD_MUTEX_INITIALIZER), - mRoleSwitchLock(PTHREAD_MUTEX_INITIALIZER), - mPartnerLock(PTHREAD_MUTEX_INITIALIZER), - mPartnerUp(false) { + : mLock(PTHREAD_MUTEX_INITIALIZER), + mRoleSwitchLock(PTHREAD_MUTEX_INITIALIZER), + mPartnerLock(PTHREAD_MUTEX_INITIALIZER), + mPartnerUp(false) { pthread_condattr_t attr; if (pthread_condattr_init(&attr)) { ALOGE("pthread_condattr_init failed: %s", strerror(errno)); @@ -226,7 +218,7 @@ Usb::Usb() ALOGE("pthread_condattr_setclock failed: %s", strerror(errno)); abort(); } - if (pthread_cond_init(&mPartnerCV, &attr)) { + if (pthread_cond_init(&mPartnerCV, &attr)) { ALOGE("pthread_cond_init failed: %s", strerror(errno)); abort(); } @@ -236,185 +228,175 @@ Usb::Usb() } } +Return Usb::switchRole(const hidl_string& portName, const PortRole& newRole) { + std::string filename = appendRoleNodeHelper(std::string(portName.c_str()), newRole.type); + std::string written; + FILE* fp; + bool roleSwitch = false; -Return Usb::switchRole(const hidl_string &portName, - const PortRole &newRole) { - std::string filename = - appendRoleNodeHelper(std::string(portName.c_str()), newRole.type); - std::string written; - FILE *fp; - bool roleSwitch = false; + if (filename == "") { + ALOGE("Fatal: invalid node type"); + return Void(); + } - if (filename == "") { - ALOGE("Fatal: invalid node type"); - return Void(); - } + pthread_mutex_lock(&mRoleSwitchLock); - pthread_mutex_lock(&mRoleSwitchLock); + ALOGI("filename write: %s role:%s", filename.c_str(), convertRoletoString(newRole).c_str()); - ALOGI("filename write: %s role:%s", filename.c_str(), - convertRoletoString(newRole).c_str()); - - if (newRole.type == PortRoleType::MODE) { - roleSwitch = switchMode(portName, newRole, this); - } else { - fp = fopen(filename.c_str(), "w"); - if (fp != NULL) { - int ret = fputs(convertRoletoString(newRole).c_str(), fp); - fclose(fp); - if ((ret != EOF) && !readFile(filename, &written)) { - extractRole(&written); - ALOGI("written: %s", written.c_str()); - if (written == convertRoletoString(newRole)) { - roleSwitch = true; - } else { - ALOGE("Role switch failed"); - } - } else { - ALOGE("failed to update the new role"); - } + if (newRole.type == PortRoleType::MODE) { + roleSwitch = switchMode(portName, newRole, this); } else { - ALOGE("fopen failed"); - } - } - - pthread_mutex_lock(&mLock); - if (mCallback_1_0 != NULL) { - Return ret = - mCallback_1_0->notifyRoleSwitchStatus(portName, newRole, - roleSwitch ? Status::SUCCESS : Status::ERROR); - if (!ret.isOk()) - ALOGE("RoleSwitchStatus error %s", ret.description().c_str()); - } else { - ALOGE("Not notifying the userspace. Callback is not set"); - } - pthread_mutex_unlock(&mLock); - pthread_mutex_unlock(&mRoleSwitchLock); - - return Void(); -} - -Status getAccessoryConnected(const std::string &portName, std::string *accessory) { - std::string filename = - "/sys/class/typec/" + portName + "-partner/accessory_mode"; - - if (readFile(filename, accessory)) { - ALOGE("getAccessoryConnected: Failed to open filesystem node: %s", - filename.c_str()); - return Status::ERROR; - } - - return Status::SUCCESS; -} - -Status getCurrentRoleHelper(const std::string &portName, bool connected, - PortRoleType type, uint32_t *currentRole) { - std::string filename; - std::string roleName; - std::string accessory; - - // Mode - - if (type == PortRoleType::POWER_ROLE) { - filename = "/sys/class/typec/" + portName + "/power_role"; - *currentRole = static_cast(PortPowerRole::NONE); - } else if (type == PortRoleType::DATA_ROLE) { - filename = "/sys/class/typec/" + portName + "/data_role"; - *currentRole = static_cast(PortDataRole::NONE); - } else if (type == PortRoleType::MODE) { - filename = "/sys/class/typec/" + portName + "/data_role"; - *currentRole = static_cast(PortMode_1_1::NONE); - } else { - return Status::ERROR; - } - - if (!connected) return Status::SUCCESS; - - if (type == PortRoleType::MODE) { - if (getAccessoryConnected(portName, &accessory) != Status::SUCCESS) { - return Status::ERROR; - } - if (accessory == "analog_audio") { - *currentRole = static_cast(PortMode_1_1::AUDIO_ACCESSORY); - return Status::SUCCESS; - } else if (accessory == "debug") { - *currentRole = static_cast(PortMode_1_1::DEBUG_ACCESSORY); - return Status::SUCCESS; - } - } - - if (readFile(filename, &roleName)) { - ALOGE("getCurrentRole: Failed to open filesystem node: %s", - filename.c_str()); - return Status::ERROR; - } - - extractRole(&roleName); - - if (roleName == "source") { - *currentRole = static_cast(PortPowerRole::SOURCE); - } else if (roleName == "sink") { - *currentRole = static_cast(PortPowerRole::SINK); - } else if (roleName == "host") { - if (type == PortRoleType::DATA_ROLE) - *currentRole = static_cast(PortDataRole::HOST); - else - *currentRole = static_cast(PortMode_1_1::DFP); - } else if (roleName == "device") { - if (type == PortRoleType::DATA_ROLE) - *currentRole = static_cast(PortDataRole::DEVICE); - else - *currentRole = static_cast(PortMode_1_1::UFP); - } else if (roleName != "none") { - /* case for none has already been addressed. - * so we check if the role isnt none. - */ - return Status::UNRECOGNIZED_ROLE; - } - - return Status::SUCCESS; -} - -Status getTypeCPortNamesHelper(std::unordered_map *names) { - DIR *dp; - - dp = opendir("/sys/class/typec"); - if (dp != NULL) { - struct dirent *ep; - - while ((ep = readdir(dp))) { - if (ep->d_type == DT_LNK) { - if (std::string::npos == std::string(ep->d_name).find("-partner")) { - std::unordered_map::const_iterator portName = - names->find(ep->d_name); - if (portName == names->end()) { - names->insert({ep->d_name, false}); - } + fp = fopen(filename.c_str(), "w"); + if (fp != NULL) { + int ret = fputs(convertRoletoString(newRole).c_str(), fp); + fclose(fp); + if ((ret != EOF) && !readFile(filename, &written)) { + extractRole(&written); + ALOGI("written: %s", written.c_str()); + if (written == convertRoletoString(newRole)) { + roleSwitch = true; + } else { + ALOGE("Role switch failed"); + } + } else { + ALOGE("failed to update the new role"); + } } else { - (*names)[std::strtok(ep->d_name, "-")] = true; + ALOGE("fopen failed"); } - } } - closedir(dp); - return Status::SUCCESS; - } - ALOGE("Failed to open /sys/class/typec"); - return Status::ERROR; + pthread_mutex_lock(&mLock); + if (mCallback_1_0 != NULL) { + Return ret = mCallback_1_0->notifyRoleSwitchStatus( + portName, newRole, roleSwitch ? Status::SUCCESS : Status::ERROR); + if (!ret.isOk()) ALOGE("RoleSwitchStatus error %s", ret.description().c_str()); + } else { + ALOGE("Not notifying the userspace. Callback is not set"); + } + pthread_mutex_unlock(&mLock); + pthread_mutex_unlock(&mRoleSwitchLock); + + return Void(); } -bool canSwitchRoleHelper(const std::string &portName, PortRoleType /*type*/) { - std::string filename = - "/sys/class/typec/" + portName + "-partner/supports_usb_power_delivery"; - std::string supportsPD; +Status getAccessoryConnected(const std::string& portName, std::string* accessory) { + std::string filename = "/sys/class/typec/" + portName + "-partner/accessory_mode"; - if (!readFile(filename, &supportsPD)) { - if (supportsPD == "yes") { - return true; + if (readFile(filename, accessory)) { + ALOGE("getAccessoryConnected: Failed to open filesystem node: %s", filename.c_str()); + return Status::ERROR; } - } - return false; + return Status::SUCCESS; +} + +Status getCurrentRoleHelper(const std::string& portName, bool connected, PortRoleType type, + uint32_t* currentRole) { + std::string filename; + std::string roleName; + std::string accessory; + + // Mode + + if (type == PortRoleType::POWER_ROLE) { + filename = "/sys/class/typec/" + portName + "/power_role"; + *currentRole = static_cast(PortPowerRole::NONE); + } else if (type == PortRoleType::DATA_ROLE) { + filename = "/sys/class/typec/" + portName + "/data_role"; + *currentRole = static_cast(PortDataRole::NONE); + } else if (type == PortRoleType::MODE) { + filename = "/sys/class/typec/" + portName + "/data_role"; + *currentRole = static_cast(PortMode_1_1::NONE); + } else { + return Status::ERROR; + } + + if (!connected) return Status::SUCCESS; + + if (type == PortRoleType::MODE) { + if (getAccessoryConnected(portName, &accessory) != Status::SUCCESS) { + return Status::ERROR; + } + if (accessory == "analog_audio") { + *currentRole = static_cast(PortMode_1_1::AUDIO_ACCESSORY); + return Status::SUCCESS; + } else if (accessory == "debug") { + *currentRole = static_cast(PortMode_1_1::DEBUG_ACCESSORY); + return Status::SUCCESS; + } + } + + if (readFile(filename, &roleName)) { + ALOGE("getCurrentRole: Failed to open filesystem node: %s", filename.c_str()); + return Status::ERROR; + } + + extractRole(&roleName); + + if (roleName == "source") { + *currentRole = static_cast(PortPowerRole::SOURCE); + } else if (roleName == "sink") { + *currentRole = static_cast(PortPowerRole::SINK); + } else if (roleName == "host") { + if (type == PortRoleType::DATA_ROLE) + *currentRole = static_cast(PortDataRole::HOST); + else + *currentRole = static_cast(PortMode_1_1::DFP); + } else if (roleName == "device") { + if (type == PortRoleType::DATA_ROLE) + *currentRole = static_cast(PortDataRole::DEVICE); + else + *currentRole = static_cast(PortMode_1_1::UFP); + } else if (roleName != "none") { + /* case for none has already been addressed. + * so we check if the role isnt none. + */ + return Status::UNRECOGNIZED_ROLE; + } + + return Status::SUCCESS; +} + +Status getTypeCPortNamesHelper(std::unordered_map* names) { + DIR* dp; + + dp = opendir("/sys/class/typec"); + if (dp != NULL) { + struct dirent* ep; + + while ((ep = readdir(dp))) { + if (ep->d_type == DT_LNK) { + if (std::string::npos == std::string(ep->d_name).find("-partner")) { + std::unordered_map::const_iterator portName = + names->find(ep->d_name); + if (portName == names->end()) { + names->insert({ep->d_name, false}); + } + } else { + (*names)[std::strtok(ep->d_name, "-")] = true; + } + } + } + closedir(dp); + return Status::SUCCESS; + } + + ALOGE("Failed to open /sys/class/typec"); + return Status::ERROR; +} + +bool canSwitchRoleHelper(const std::string& portName, PortRoleType /*type*/) { + std::string filename = "/sys/class/typec/" + portName + "-partner/supports_usb_power_delivery"; + std::string supportsPD; + + if (!readFile(filename, &supportsPD)) { + if (supportsPD == "yes") { + return true; + } + } + + return false; } /* @@ -422,349 +404,345 @@ bool canSwitchRoleHelper(const std::string &portName, PortRoleType /*type*/) { * The caller of this method would reconstruct the V1_0::PortStatus * object if required. */ -Status getPortStatusHelper(hidl_vec *currentPortStatus_1_1, - bool V1_0) { - std::unordered_map names; - Status result = getTypeCPortNamesHelper(&names); - int i = -1; +Status getPortStatusHelper(hidl_vec* currentPortStatus_1_1, bool V1_0) { + std::unordered_map names; + Status result = getTypeCPortNamesHelper(&names); + int i = -1; - if (result == Status::SUCCESS) { - currentPortStatus_1_1->resize(names.size()); - for (std::pair port : names) { - i++; - ALOGI("%s", port.first.c_str()); - (*currentPortStatus_1_1)[i].status.portName = port.first; + if (result == Status::SUCCESS) { + currentPortStatus_1_1->resize(names.size()); + for (std::pair port : names) { + i++; + ALOGI("%s", port.first.c_str()); + (*currentPortStatus_1_1)[i].status.portName = port.first; - uint32_t currentRole; - if (getCurrentRoleHelper(port.first, port.second, - PortRoleType::POWER_ROLE, - ¤tRole) == Status::SUCCESS) { - (*currentPortStatus_1_1)[i].status.currentPowerRole = - static_cast(currentRole); - } else { - ALOGE("Error while retreiving portNames"); - goto done; - } + uint32_t currentRole; + if (getCurrentRoleHelper(port.first, port.second, PortRoleType::POWER_ROLE, + ¤tRole) == Status::SUCCESS) { + (*currentPortStatus_1_1)[i].status.currentPowerRole = + static_cast(currentRole); + } else { + ALOGE("Error while retreiving portNames"); + goto done; + } - if (getCurrentRoleHelper(port.first, port.second, PortRoleType::DATA_ROLE, - ¤tRole) == Status::SUCCESS) { - (*currentPortStatus_1_1)[i].status.currentDataRole = - static_cast(currentRole); - } else { - ALOGE("Error while retreiving current port role"); - goto done; - } + if (getCurrentRoleHelper(port.first, port.second, PortRoleType::DATA_ROLE, + ¤tRole) == Status::SUCCESS) { + (*currentPortStatus_1_1)[i].status.currentDataRole = + static_cast(currentRole); + } else { + ALOGE("Error while retreiving current port role"); + goto done; + } - if (getCurrentRoleHelper(port.first, port.second, PortRoleType::MODE, - ¤tRole) == Status::SUCCESS) { - (*currentPortStatus_1_1)[i].currentMode = - static_cast(currentRole); - (*currentPortStatus_1_1)[i].status.currentMode = - static_cast(currentRole); - } else { - ALOGE("Error while retreiving current data role"); - goto done; - } + if (getCurrentRoleHelper(port.first, port.second, PortRoleType::MODE, ¤tRole) == + Status::SUCCESS) { + (*currentPortStatus_1_1)[i].currentMode = static_cast(currentRole); + (*currentPortStatus_1_1)[i].status.currentMode = + static_cast(currentRole); + } else { + ALOGE("Error while retreiving current data role"); + goto done; + } - (*currentPortStatus_1_1)[i].status.canChangeMode = true; - (*currentPortStatus_1_1)[i].status.canChangeDataRole = - port.second ? canSwitchRoleHelper(port.first, PortRoleType::DATA_ROLE) - : false; - (*currentPortStatus_1_1)[i].status.canChangePowerRole = - port.second - ? canSwitchRoleHelper(port.first, PortRoleType::POWER_ROLE) - : false; + (*currentPortStatus_1_1)[i].status.canChangeMode = true; + (*currentPortStatus_1_1)[i].status.canChangeDataRole = + port.second ? canSwitchRoleHelper(port.first, PortRoleType::DATA_ROLE) : false; + (*currentPortStatus_1_1)[i].status.canChangePowerRole = + port.second ? canSwitchRoleHelper(port.first, PortRoleType::POWER_ROLE) : false; - ALOGI("connected:%d canChangeMode:%d canChagedata:%d canChangePower:%d", - port.second, (*currentPortStatus_1_1)[i].status.canChangeMode, - (*currentPortStatus_1_1)[i].status.canChangeDataRole, - (*currentPortStatus_1_1)[i].status.canChangePowerRole); + ALOGI("connected:%d canChangeMode:%d canChagedata:%d canChangePower:%d", port.second, + (*currentPortStatus_1_1)[i].status.canChangeMode, + (*currentPortStatus_1_1)[i].status.canChangeDataRole, + (*currentPortStatus_1_1)[i].status.canChangePowerRole); - if (V1_0) { - (*currentPortStatus_1_1)[i].status.supportedModes = V1_0::PortMode::DFP; - } else { - (*currentPortStatus_1_1)[i].supportedModes = PortMode_1_1::UFP | PortMode_1_1::DFP; - (*currentPortStatus_1_1)[i].status.supportedModes = V1_0::PortMode::NONE; - (*currentPortStatus_1_1)[i].status.currentMode = V1_0::PortMode::NONE; - } + if (V1_0) { + (*currentPortStatus_1_1)[i].status.supportedModes = V1_0::PortMode::DFP; + } else { + (*currentPortStatus_1_1)[i].supportedModes = PortMode_1_1::UFP | PortMode_1_1::DFP; + (*currentPortStatus_1_1)[i].status.supportedModes = V1_0::PortMode::NONE; + (*currentPortStatus_1_1)[i].status.currentMode = V1_0::PortMode::NONE; + } + } + return Status::SUCCESS; } - return Status::SUCCESS; - } done: - return Status::ERROR; + return Status::ERROR; } Return Usb::queryPortStatus() { - hidl_vec currentPortStatus_1_1; - hidl_vec currentPortStatus; - Status status; - sp callback_V1_1 = IUsbCallback::castFrom(mCallback_1_0); + hidl_vec currentPortStatus_1_1; + hidl_vec currentPortStatus; + Status status; + sp callback_V1_1 = IUsbCallback::castFrom(mCallback_1_0); - pthread_mutex_lock(&mLock); - if (mCallback_1_0 != NULL) { - if (callback_V1_1 != NULL) { - status = getPortStatusHelper(¤tPortStatus_1_1, false); + pthread_mutex_lock(&mLock); + if (mCallback_1_0 != NULL) { + if (callback_V1_1 != NULL) { + status = getPortStatusHelper(¤tPortStatus_1_1, false); + } else { + status = getPortStatusHelper(¤tPortStatus_1_1, true); + currentPortStatus.resize(currentPortStatus_1_1.size()); + for (unsigned long i = 0; i < currentPortStatus_1_1.size(); i++) + currentPortStatus[i] = currentPortStatus_1_1[i].status; + } + + Return ret; + + if (callback_V1_1 != NULL) + ret = callback_V1_1->notifyPortStatusChange_1_1(currentPortStatus_1_1, status); + else + ret = mCallback_1_0->notifyPortStatusChange(currentPortStatus, status); + + if (!ret.isOk()) ALOGE("queryPortStatus_1_1 error %s", ret.description().c_str()); } else { - status = getPortStatusHelper(¤tPortStatus_1_1, true); - currentPortStatus.resize(currentPortStatus_1_1.size()); - for (unsigned long i = 0; i < currentPortStatus_1_1.size(); i++) - currentPortStatus[i] = currentPortStatus_1_1[i].status; + ALOGI("Notifying userspace skipped. Callback is NULL"); } + pthread_mutex_unlock(&mLock); - Return ret; - - if (callback_V1_1 != NULL) - ret = callback_V1_1->notifyPortStatusChange_1_1(currentPortStatus_1_1, status); - else - ret = mCallback_1_0->notifyPortStatusChange(currentPortStatus, status); - - if (!ret.isOk()) - ALOGE("queryPortStatus_1_1 error %s", ret.description().c_str()); - } else { - ALOGI("Notifying userspace skipped. Callback is NULL"); - } - pthread_mutex_unlock(&mLock); - - return Void(); + return Void(); } struct data { - int uevent_fd; - android::hardware::usb::V1_1::implementation::Usb *usb; + int uevent_fd; + android::hardware::usb::V1_1::implementation::Usb* usb; }; -static void uevent_event(uint32_t /*epevents*/, struct data *payload) { - char msg[UEVENT_MSG_LEN + 2]; - char *cp; - int n; +static void uevent_event(uint32_t /*epevents*/, struct data* payload) { + char msg[UEVENT_MSG_LEN + 2]; + char* cp; + int n; - n = uevent_kernel_multicast_recv(payload->uevent_fd, msg, UEVENT_MSG_LEN); - if (n <= 0) return; - if (n >= UEVENT_MSG_LEN) /* overflow -- discard */ - return; + n = uevent_kernel_multicast_recv(payload->uevent_fd, msg, UEVENT_MSG_LEN); + if (n <= 0) return; + if (n >= UEVENT_MSG_LEN) /* overflow -- discard */ + return; - msg[n] = '\0'; - msg[n + 1] = '\0'; - cp = msg; + msg[n] = '\0'; + msg[n + 1] = '\0'; + cp = msg; - while (*cp) { - std::cmatch match; - if (std::regex_match(cp, std::regex("(add)(.*)(-partner)"))) { - ALOGI("partner added"); - pthread_mutex_lock(&payload->usb->mPartnerLock); - payload->usb->mPartnerUp = true; - pthread_cond_signal(&payload->usb->mPartnerCV); - pthread_mutex_unlock(&payload->usb->mPartnerLock); - } else if (!strncmp(cp, "DEVTYPE=typec_", strlen("DEVTYPE=typec_"))) { - hidl_vec currentPortStatus_1_1; - ALOGI("uevent received %s", cp); - pthread_mutex_lock(&payload->usb->mLock); - if (payload->usb->mCallback_1_0 != NULL) { - sp callback_V1_1 = IUsbCallback::castFrom(payload->usb->mCallback_1_0); - Return ret; + while (*cp) { + std::cmatch match; + if (std::regex_match(cp, std::regex("(add)(.*)(-partner)"))) { + ALOGI("partner added"); + pthread_mutex_lock(&payload->usb->mPartnerLock); + payload->usb->mPartnerUp = true; + pthread_cond_signal(&payload->usb->mPartnerCV); + pthread_mutex_unlock(&payload->usb->mPartnerLock); + } else if (!strncmp(cp, "DEVTYPE=typec_", strlen("DEVTYPE=typec_"))) { + hidl_vec currentPortStatus_1_1; + ALOGI("uevent received %s", cp); + pthread_mutex_lock(&payload->usb->mLock); + if (payload->usb->mCallback_1_0 != NULL) { + sp callback_V1_1 = + IUsbCallback::castFrom(payload->usb->mCallback_1_0); + Return ret; - // V1_1 callback - if (callback_V1_1 != NULL) { - Status status = getPortStatusHelper(¤tPortStatus_1_1, false); - ret = callback_V1_1->notifyPortStatusChange_1_1( - currentPortStatus_1_1, status); - } else { // V1_0 callback - Status status = getPortStatusHelper(¤tPortStatus_1_1, true); + // V1_1 callback + if (callback_V1_1 != NULL) { + Status status = getPortStatusHelper(¤tPortStatus_1_1, false); + ret = callback_V1_1->notifyPortStatusChange_1_1(currentPortStatus_1_1, status); + } else { // V1_0 callback + Status status = getPortStatusHelper(¤tPortStatus_1_1, true); - /* - * Copying the result from getPortStatusHelper - * into V1_0::PortStatus to pass back through - * the V1_0 callback object. - */ - hidl_vec currentPortStatus; - currentPortStatus.resize(currentPortStatus_1_1.size()); - for (unsigned long i = 0; i < currentPortStatus_1_1.size(); i++) - currentPortStatus[i] = currentPortStatus_1_1[i].status; + /* + * Copying the result from getPortStatusHelper + * into V1_0::PortStatus to pass back through + * the V1_0 callback object. + */ + hidl_vec currentPortStatus; + currentPortStatus.resize(currentPortStatus_1_1.size()); + for (unsigned long i = 0; i < currentPortStatus_1_1.size(); i++) + currentPortStatus[i] = currentPortStatus_1_1[i].status; - ret = payload->usb->mCallback_1_0->notifyPortStatusChange( - currentPortStatus, status); + ret = payload->usb->mCallback_1_0->notifyPortStatusChange(currentPortStatus, + status); + } + if (!ret.isOk()) ALOGE("error %s", ret.description().c_str()); + } else { + ALOGI("Notifying userspace skipped. Callback is NULL"); + } + pthread_mutex_unlock(&payload->usb->mLock); + + // Role switch is not in progress and port is in disconnected state + if (!pthread_mutex_trylock(&payload->usb->mRoleSwitchLock)) { + for (unsigned long i = 0; i < currentPortStatus_1_1.size(); i++) { + DIR* dp = opendir( + std::string( + "/sys/class/typec/" + + std::string(currentPortStatus_1_1[i].status.portName.c_str()) + + "-partner") + .c_str()); + if (dp == NULL) { + // PortRole role = {.role = static_cast(PortMode::UFP)}; + switchToDrp(currentPortStatus_1_1[i].status.portName); + } else { + closedir(dp); + } + } + pthread_mutex_unlock(&payload->usb->mRoleSwitchLock); + } + break; + } else if (std::regex_match(cp, match, + std::regex("add@(/devices/soc/a800000\\.ssusb/a800000\\.dwc3/" + "xhci-hcd\\.0\\.auto/" + "usb\\d/\\d-\\d)/.*"))) { + if (match.size() == 2) { + std::csub_match submatch = match[1]; + checkUsbDeviceAutoSuspend("/sys" + submatch.str()); + } } - if (!ret.isOk()) ALOGE("error %s", ret.description().c_str()); - } else { - ALOGI("Notifying userspace skipped. Callback is NULL"); - } - pthread_mutex_unlock(&payload->usb->mLock); - //Role switch is not in progress and port is in disconnected state - if (!pthread_mutex_trylock(&payload->usb->mRoleSwitchLock)) { - for (unsigned long i = 0; i < currentPortStatus_1_1.size(); i++) { - DIR *dp = opendir(std::string("/sys/class/typec/" - + std::string(currentPortStatus_1_1[i].status.portName.c_str()) - + "-partner").c_str()); - if (dp == NULL) { - //PortRole role = {.role = static_cast(PortMode::UFP)}; - switchToDrp(currentPortStatus_1_1[i].status.portName); - } else { - closedir(dp); - } + /* advance to after the next \0 */ + while (*cp++) { } - pthread_mutex_unlock(&payload->usb->mRoleSwitchLock); - } - break; - } else if (std::regex_match(cp, match, - std::regex("add@(/devices/soc/a800000\\.ssusb/a800000\\.dwc3/xhci-hcd\\.0\\.auto/" - "usb\\d/\\d-\\d)/.*"))) { - if (match.size() == 2) { - std::csub_match submatch = match[1]; - checkUsbDeviceAutoSuspend("/sys" + submatch.str()); - } } - - /* advance to after the next \0 */ - while (*cp++) {} - } } -void *work(void *param) { - int epoll_fd, uevent_fd; - struct epoll_event ev; - int nevents = 0; - struct data payload; +void* work(void* param) { + int epoll_fd, uevent_fd; + struct epoll_event ev; + int nevents = 0; + struct data payload; - ALOGE("creating thread"); + ALOGE("creating thread"); - uevent_fd = uevent_open_socket(64 * 1024, true); + uevent_fd = uevent_open_socket(64 * 1024, true); - if (uevent_fd < 0) { - ALOGE("uevent_init: uevent_open_socket failed\n"); - return NULL; - } - - payload.uevent_fd = uevent_fd; - payload.usb = (android::hardware::usb::V1_1::implementation::Usb *)param; - - fcntl(uevent_fd, F_SETFL, O_NONBLOCK); - - ev.events = EPOLLIN; - ev.data.ptr = (void *)uevent_event; - - epoll_fd = epoll_create(64); - if (epoll_fd == -1) { - ALOGE("epoll_create failed; errno=%d", errno); - goto error; - } - - if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, uevent_fd, &ev) == -1) { - ALOGE("epoll_ctl failed; errno=%d", errno); - goto error; - } - - while (!destroyThread) { - struct epoll_event events[64]; - - nevents = epoll_wait(epoll_fd, events, 64, -1); - if (nevents == -1) { - if (errno == EINTR) continue; - ALOGE("usb epoll_wait failed; errno=%d", errno); - break; + if (uevent_fd < 0) { + ALOGE("uevent_init: uevent_open_socket failed\n"); + return NULL; } - for (int n = 0; n < nevents; ++n) { - if (events[n].data.ptr) - (*(void (*)(int, struct data *payload))events[n].data.ptr)( - events[n].events, &payload); - } - } + payload.uevent_fd = uevent_fd; + payload.usb = (android::hardware::usb::V1_1::implementation::Usb*)param; - ALOGI("exiting worker thread"); + fcntl(uevent_fd, F_SETFL, O_NONBLOCK); + + ev.events = EPOLLIN; + ev.data.ptr = (void*)uevent_event; + + epoll_fd = epoll_create(64); + if (epoll_fd == -1) { + ALOGE("epoll_create failed; errno=%d", errno); + goto error; + } + + if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, uevent_fd, &ev) == -1) { + ALOGE("epoll_ctl failed; errno=%d", errno); + goto error; + } + + while (!destroyThread) { + struct epoll_event events[64]; + + nevents = epoll_wait(epoll_fd, events, 64, -1); + if (nevents == -1) { + if (errno == EINTR) continue; + ALOGE("usb epoll_wait failed; errno=%d", errno); + break; + } + + for (int n = 0; n < nevents; ++n) { + if (events[n].data.ptr) + (*(void (*)(int, struct data* payload))events[n].data.ptr)(events[n].events, + &payload); + } + } + + ALOGI("exiting worker thread"); error: - close(uevent_fd); + close(uevent_fd); - if (epoll_fd >= 0) close(epoll_fd); + if (epoll_fd >= 0) close(epoll_fd); - return NULL; + return NULL; } void sighandler(int sig) { - if (sig == SIGUSR1) { - destroyThread = true; - ALOGI("destroy set"); - return; - } - signal(SIGUSR1, sighandler); + if (sig == SIGUSR1) { + destroyThread = true; + ALOGI("destroy set"); + return; + } + signal(SIGUSR1, sighandler); } -Return Usb::setCallback(const sp &callback) { +Return Usb::setCallback(const sp& callback) { + sp callback_V1_1 = IUsbCallback::castFrom(callback); - sp callback_V1_1 = IUsbCallback::castFrom(callback); + if (callback != NULL) + if (callback_V1_1 == NULL) ALOGI("Registering 1.0 callback"); - if (callback != NULL) - if (callback_V1_1 == NULL) - ALOGI("Registering 1.0 callback"); - - pthread_mutex_lock(&mLock); - /* - * When both the old callback and new callback values are NULL, - * there is no need to spin off the worker thread. - * When both the values are not NULL, we would already have a - * worker thread running, so updating the callback object would - * be suffice. - */ - if ((mCallback_1_0 == NULL && callback == NULL) || - (mCallback_1_0 != NULL && callback != NULL)) { + pthread_mutex_lock(&mLock); /* - * Always store as V1_0 callback object. Type cast to V1_1 - * when the callback is actually invoked. + * When both the old callback and new callback values are NULL, + * there is no need to spin off the worker thread. + * When both the values are not NULL, we would already have a + * worker thread running, so updating the callback object would + * be suffice. */ - mCallback_1_0 = callback; - pthread_mutex_unlock(&mLock); - return Void(); - } - - mCallback_1_0 = callback; - ALOGI("registering callback"); - - // Kill the worker thread if the new callback is NULL. - if (mCallback_1_0 == NULL) { - pthread_mutex_unlock(&mLock); - if (!pthread_kill(mPoll, SIGUSR1)) { - pthread_join(mPoll, NULL); - ALOGI("pthread destroyed"); + if ((mCallback_1_0 == NULL && callback == NULL) || + (mCallback_1_0 != NULL && callback != NULL)) { + /* + * Always store as V1_0 callback object. Type cast to V1_1 + * when the callback is actually invoked. + */ + mCallback_1_0 = callback; + pthread_mutex_unlock(&mLock); + return Void(); } + + mCallback_1_0 = callback; + ALOGI("registering callback"); + + // Kill the worker thread if the new callback is NULL. + if (mCallback_1_0 == NULL) { + pthread_mutex_unlock(&mLock); + if (!pthread_kill(mPoll, SIGUSR1)) { + pthread_join(mPoll, NULL); + ALOGI("pthread destroyed"); + } + return Void(); + } + + destroyThread = false; + signal(SIGUSR1, sighandler); + + /* + * Create a background thread if the old callback value is NULL + * and being updated with a new value. + */ + if (pthread_create(&mPoll, NULL, work, this)) { + ALOGE("pthread creation failed %d", errno); + mCallback_1_0 = NULL; + } + + pthread_mutex_unlock(&mLock); return Void(); - } - - destroyThread = false; - signal(SIGUSR1, sighandler); - - /* - * Create a background thread if the old callback value is NULL - * and being updated with a new value. - */ - if (pthread_create(&mPoll, NULL, work, this)) { - ALOGE("pthread creation failed %d", errno); - mCallback_1_0 = NULL; - } - - pthread_mutex_unlock(&mLock); - return Void(); } /* * whitelisting USB device idProduct and idVendor to allow auto suspend. */ -static bool canProductAutoSuspend(const std::string &deviceIdVendor, - const std::string &deviceIdProduct) { - if (deviceIdVendor == GOOGLE_USB_VENDOR_ID_STR && - deviceIdProduct == GOOGLE_USBC_35_ADAPTER_UNPLUGGED_ID_STR) { - return true; - } - return false; +static bool canProductAutoSuspend(const std::string& deviceIdVendor, + const std::string& deviceIdProduct) { + if (deviceIdVendor == GOOGLE_USB_VENDOR_ID_STR && + deviceIdProduct == GOOGLE_USBC_35_ADAPTER_UNPLUGGED_ID_STR) { + return true; + } + return false; } -static bool canUsbDeviceAutoSuspend(const std::string &devicePath) { - std::string deviceIdVendor; - std::string deviceIdProduct; - readFile(devicePath + "/idVendor", &deviceIdVendor); - readFile(devicePath + "/idProduct", &deviceIdProduct); +static bool canUsbDeviceAutoSuspend(const std::string& devicePath) { + std::string deviceIdVendor; + std::string deviceIdProduct; + readFile(devicePath + "/idVendor", &deviceIdVendor); + readFile(devicePath + "/idProduct", &deviceIdProduct); - // deviceIdVendor and deviceIdProduct will be empty strings if readFile fails - return canProductAutoSuspend(deviceIdVendor, deviceIdProduct); + // deviceIdVendor and deviceIdProduct will be empty strings if readFile fails + return canProductAutoSuspend(deviceIdVendor, deviceIdProduct); } /* @@ -773,18 +751,18 @@ static bool canUsbDeviceAutoSuspend(const std::string &devicePath) { * necessary. */ void checkUsbDeviceAutoSuspend(const std::string& devicePath) { - /* - * Currently we only actively enable devices that should be autosuspended, and leave others - * to the defualt. - */ - if (canUsbDeviceAutoSuspend(devicePath)) { - ALOGI("auto suspend usb device %s", devicePath.c_str()); - writeFile(devicePath + "/power/control", "auto"); - } + /* + * Currently we only actively enable devices that should be autosuspended, and leave others + * to the defualt. + */ + if (canUsbDeviceAutoSuspend(devicePath)) { + ALOGI("auto suspend usb device %s", devicePath.c_str()); + writeFile(devicePath + "/power/control", "auto"); + } } } // namespace implementation -} // namespace V1_0 +} // namespace V1_1 } // namespace usb } // namespace hardware } // namespace android diff --git a/universal7885-common/usb/typec/Usb.h b/universal7885-common/usb/typec/Usb.h index 78be2f9..daa4977 100644 --- a/universal7885-common/usb/typec/Usb.h +++ b/universal7885-common/usb/typec/Usb.h @@ -2,8 +2,8 @@ #define ANDROID_HARDWARE_USB_V1_1_USB_H #include -#include #include +#include #include #include @@ -20,10 +20,17 @@ namespace usb { namespace V1_1 { namespace implementation { -using ::android::hardware::usb::V1_0::PortRole; -using ::android::hardware::usb::V1_0::PortRoleType; +using ::android::sp; +using ::android::hardware::hidl_array; +using ::android::hardware::hidl_memory; +using ::android::hardware::hidl_string; +using ::android::hardware::hidl_vec; +using ::android::hardware::Return; +using ::android::hardware::Void; using ::android::hardware::usb::V1_0::PortDataRole; using ::android::hardware::usb::V1_0::PortPowerRole; +using ::android::hardware::usb::V1_0::PortRole; +using ::android::hardware::usb::V1_0::PortRoleType; using ::android::hardware::usb::V1_0::Status; using ::android::hardware::usb::V1_1::IUsb; using ::android::hardware::usb::V1_1::IUsbCallback; @@ -31,13 +38,6 @@ using ::android::hardware::usb::V1_1::PortMode_1_1; using ::android::hardware::usb::V1_1::PortStatus_1_1; using ::android::hidl::base::V1_0::DebugInfo; using ::android::hidl::base::V1_0::IBase; -using ::android::hardware::hidl_array; -using ::android::hardware::hidl_memory; -using ::android::hardware::hidl_string; -using ::android::hardware::hidl_vec; -using ::android::hardware::Return; -using ::android::hardware::Void; -using ::android::sp; struct Usb : public IUsb { Usb(); @@ -46,7 +46,6 @@ struct Usb : public IUsb { Return setCallback(const sp& callback) override; Return queryPortStatus() override; - sp mCallback_1_0; // Protects mCallback variable pthread_mutex_t mLock; @@ -59,12 +58,12 @@ struct Usb : public IUsb { // Variable to signal partner coming back online after type switch bool mPartnerUp; - private: - pthread_t mPoll; + private: + pthread_t mPoll; }; } // namespace implementation -} // namespace V1_0 +} // namespace V1_1 } // namespace usb } // namespace hardware } // namespace android diff --git a/universal7885-common/usb/typec/service.cpp b/universal7885-common/usb/typec/service.cpp index 06c23f4..7b2bbf9 100644 --- a/universal7885-common/usb/typec/service.cpp +++ b/universal7885-common/usb/typec/service.cpp @@ -29,8 +29,8 @@ using android::hardware::joinRpcThreadpool; using android::hardware::usb::V1_1::IUsb; using android::hardware::usb::V1_1::implementation::Usb; -using android::status_t; using android::OK; +using android::status_t; int main() { android::sp service = new Usb(); @@ -48,5 +48,4 @@ int main() { // Under noraml cases, execution will not reach this line. ALOGI("USB HAL failed to join thread pool."); return 1; - }