universal7885: run clang-format based on system-clang-format

* On every *.cpp *.h files

Signed-off-by: roynatech2544 <whiteshell2544@naver.com>
This commit is contained in:
roynatech2544 2021-12-12 20:37:53 +09:00
commit 098179eabb
No known key found for this signature in database
GPG key ID: 9675C32163D88D30
47 changed files with 1545 additions and 1709 deletions

View file

@ -41,10 +41,12 @@ Lights::Lights() {
mLights.emplace(LightType::BACKLIGHT, mLights.emplace(LightType::BACKLIGHT,
std::bind(&Lights::handleBacklight, this, std::placeholders::_1)); std::bind(&Lights::handleBacklight, this, std::placeholders::_1));
#ifdef BUTTON_BRIGHTNESS_NODE #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 */ #endif /* BUTTON_BRIGHTNESS_NODE */
#ifdef LED_BLINK_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, mLights.emplace(LightType::NOTIFICATIONS,
std::bind(&Lights::handleNotifications, this, std::placeholders::_1)); std::bind(&Lights::handleNotifications, this, std::placeholders::_1));
mLights.emplace(LightType::ATTENTION, mLights.emplace(LightType::ATTENTION,
@ -166,7 +168,8 @@ uint32_t Lights::calibrateColor(uint32_t color, int32_t brightness) {
} }
#endif /* LED_BLINK_NODE */ #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<HwLight>* _aidl_return) { ndk::ScopedAStatus Lights::getLights(std::vector<HwLight>* _aidl_return) {
for (auto const& light : mLights) { for (auto const& light : mLights) {
@ -179,7 +182,8 @@ ndk::ScopedAStatus Lights::getLights(std::vector<HwLight> *_aidl_return) {
uint32_t Lights::rgbToBrightness(const HwLightState& state) { uint32_t Lights::rgbToBrightness(const HwLightState& state) {
uint32_t color = state.color & COLOR_MASK; 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; 8;
} }

View file

@ -10,8 +10,8 @@
#include <unordered_map> #include <unordered_map>
#include "samsung_lights.h" #include "samsung_lights.h"
using ::aidl::android::hardware::light::HwLightState;
using ::aidl::android::hardware::light::HwLight; using ::aidl::android::hardware::light::HwLight;
using ::aidl::android::hardware::light::HwLightState;
namespace aidl { namespace aidl {
namespace android { namespace android {

View file

@ -8,9 +8,9 @@
#include "Lights.h" #include "Lights.h"
#include <android-base/logging.h>
#include <android/binder_manager.h> #include <android/binder_manager.h>
#include <android/binder_process.h> #include <android/binder_process.h>
#include <android-base/logging.h>
using ::aidl::android::hardware::light::Lights; using ::aidl::android::hardware::light::Lights;

View file

@ -52,8 +52,7 @@ static int fb_idle_open(void) {
int fd; int fd;
for (auto& path : fb_idle_patch) { for (auto& path : fb_idle_patch) {
fd = open(path.c_str(), O_RDONLY); fd = open(path.c_str(), O_RDONLY);
if (fd >= 0) if (fd >= 0) return fd;
return fd;
} }
ALOGE("Unable to open fb idle state path (%d)", errno); ALOGE("Unable to open fb idle state path (%d)", errno);
return -1; return -1;
@ -62,8 +61,7 @@ static int fb_idle_open(void) {
bool InteractionHandler::Init() { bool InteractionHandler::Init() {
std::lock_guard<std::mutex> lk(mLock); std::lock_guard<std::mutex> lk(mLock);
if (mState != INTERACTION_STATE_UNINITIALIZED) if (mState != INTERACTION_STATE_UNINITIALIZED) return true;
return true;
mIdleFd = fb_idle_open(); mIdleFd = fb_idle_open();
@ -84,8 +82,7 @@ bool InteractionHandler::Init() {
void InteractionHandler::Exit() { void InteractionHandler::Exit() {
std::unique_lock<std::mutex> lk(mLock); std::unique_lock<std::mutex> lk(mLock);
if (mState == INTERACTION_STATE_UNINITIALIZED) if (mState == INTERACTION_STATE_UNINITIALIZED) return;
return;
AbortWaitLocked(); AbortWaitLocked();
mState = INTERACTION_STATE_UNINITIALIZED; mState = INTERACTION_STATE_UNINITIALIZED;
@ -186,8 +183,7 @@ void InteractionHandler::Release() {
void InteractionHandler::AbortWaitLocked() { void InteractionHandler::AbortWaitLocked() {
uint64_t val = 1; uint64_t val = 1;
ssize_t ret = write(mEventFd, &val, sizeof(val)); ssize_t ret = write(mEventFd, &val, sizeof(val));
if (ret != sizeof(val)) if (ret != sizeof(val)) ALOGW("Unable to write to event fd (%zd)", ret);
ALOGW("Unable to write to event fd (%zd)", ret);
} }
void InteractionHandler::WaitForIdle(int32_t wait_ms, int32_t timeout_ms) { void InteractionHandler::WaitForIdle(int32_t wait_ms, int32_t timeout_ms) {
@ -253,8 +249,7 @@ void InteractionHandler::Routine() {
while (true) { while (true) {
lk.lock(); lk.lock();
mCond.wait(lk, [&] { return mState != INTERACTION_STATE_IDLE; }); mCond.wait(lk, [&] { return mState != INTERACTION_STATE_IDLE; });
if (mState == INTERACTION_STATE_UNINITIALIZED) if (mState == INTERACTION_STATE_UNINITIALIZED) return;
return;
mState = INTERACTION_STATE_WAITING; mState = INTERACTION_STATE_WAITING;
lk.unlock(); lk.unlock();

View file

@ -34,8 +34,7 @@ using ::android::perfmgr::HintManager;
class PowerExt : public ::aidl::google::hardware::power::extension::pixel::BnPowerExt { class PowerExt : public ::aidl::google::hardware::power::extension::pixel::BnPowerExt {
public: public:
PowerExt(std::shared_ptr<HintManager> hm) PowerExt(std::shared_ptr<HintManager> hm) : mHintManager(hm) {}
: mHintManager(hm) {}
ndk::ScopedAStatus setMode(const std::string& mode, bool enabled) override; ndk::ScopedAStatus setMode(const std::string& mode, bool enabled) override;
ndk::ScopedAStatus isModeSupported(const std::string& mode, bool* _aidl_return) 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 setBoost(const std::string& boost, int32_t durationMs) override;

View file

@ -53,7 +53,8 @@ Vibrator::Vibrator() {
ndk::ScopedAStatus Vibrator::getCapabilities(int32_t* _aidl_return) { ndk::ScopedAStatus Vibrator::getCapabilities(int32_t* _aidl_return) {
*_aidl_return = IVibrator::CAP_ON_CALLBACK | IVibrator::CAP_PERFORM_CALLBACK | *_aidl_return = IVibrator::CAP_ON_CALLBACK | IVibrator::CAP_PERFORM_CALLBACK |
IVibrator::CAP_EXTERNAL_CONTROL /*| IVibrator::CAP_COMPOSE_EFFECTS | IVibrator::CAP_EXTERNAL_CONTROL /*| IVibrator::CAP_COMPOSE_EFFECTS |
IVibrator::CAP_ALWAYS_ON_CONTROL*/; IVibrator::CAP_ALWAYS_ON_CONTROL*/
;
if (mHasTimedOutIntensity) { if (mHasTimedOutIntensity) {
*_aidl_return = *_aidl_return | IVibrator::CAP_AMPLITUDE_CONTROL | *_aidl_return = *_aidl_return | IVibrator::CAP_AMPLITUDE_CONTROL |
@ -67,7 +68,8 @@ ndk::ScopedAStatus Vibrator::off() {
return activate(0); return activate(0);
} }
ndk::ScopedAStatus Vibrator::on(int32_t timeoutMs, const std::shared_ptr<IVibratorCallback>& callback) { ndk::ScopedAStatus Vibrator::on(int32_t timeoutMs,
const std::shared_ptr<IVibratorCallback>& callback) {
ndk::ScopedAStatus status = activate(timeoutMs); ndk::ScopedAStatus status = activate(timeoutMs);
if (callback != nullptr) { if (callback != nullptr) {
@ -84,7 +86,9 @@ ndk::ScopedAStatus Vibrator::on(int32_t timeoutMs, const std::shared_ptr<IVibrat
return status; return status;
} }
ndk::ScopedAStatus Vibrator::perform(Effect effect, EffectStrength strength, const std::shared_ptr<IVibratorCallback>& callback, int32_t* _aidl_return) { ndk::ScopedAStatus Vibrator::perform(Effect effect, EffectStrength strength,
const std::shared_ptr<IVibratorCallback>& callback,
int32_t* _aidl_return) {
ndk::ScopedAStatus status; ndk::ScopedAStatus status;
uint8_t amplitude; uint8_t amplitude;
uint32_t ms; uint32_t ms;
@ -115,14 +119,13 @@ ndk::ScopedAStatus Vibrator::perform(Effect effect, EffectStrength strength, con
} }
ndk::ScopedAStatus Vibrator::getSupportedEffects(std::vector<Effect>* _aidl_return) { ndk::ScopedAStatus Vibrator::getSupportedEffects(std::vector<Effect>* _aidl_return) {
*_aidl_return = {Effect::CLICK, Effect::DOUBLE_CLICK, Effect::HEAVY_CLICK, *_aidl_return = {
Effect::TICK, Effect::TEXTURE_TICK, Effect::THUD, Effect::POP, Effect::CLICK, Effect::DOUBLE_CLICK, Effect::HEAVY_CLICK, Effect::TICK,
Effect::RINGTONE_1, Effect::RINGTONE_2, Effect::RINGTONE_3, Effect::TEXTURE_TICK, Effect::THUD, Effect::POP, Effect::RINGTONE_1,
Effect::RINGTONE_4, Effect::RINGTONE_5, Effect::RINGTONE_6, Effect::RINGTONE_2, Effect::RINGTONE_3, Effect::RINGTONE_4, Effect::RINGTONE_5,
Effect::RINGTONE_7, Effect::RINGTONE_7, Effect::RINGTONE_8, Effect::RINGTONE_6, Effect::RINGTONE_7, Effect::RINGTONE_7, Effect::RINGTONE_8,
Effect::RINGTONE_9, Effect::RINGTONE_10, Effect::RINGTONE_11, Effect::RINGTONE_9, Effect::RINGTONE_10, Effect::RINGTONE_11, Effect::RINGTONE_12,
Effect::RINGTONE_12, Effect::RINGTONE_13, Effect::RINGTONE_14, Effect::RINGTONE_13, Effect::RINGTONE_14, Effect::RINGTONE_15};
Effect::RINGTONE_15};
return ndk::ScopedAStatus::ok(); return ndk::ScopedAStatus::ok();
} }
@ -168,15 +171,18 @@ ndk::ScopedAStatus Vibrator::getCompositionSizeMax(int32_t* /*_aidl_return*/) {
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
} }
ndk::ScopedAStatus Vibrator::getSupportedPrimitives(std::vector<CompositePrimitive>* /*_aidl_return*/) { ndk::ScopedAStatus Vibrator::getSupportedPrimitives(
std::vector<CompositePrimitive>* /*_aidl_return*/) {
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); 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); return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
} }
ndk::ScopedAStatus Vibrator::compose(const std::vector<CompositeEffect>& /*composite*/, const std::shared_ptr<IVibratorCallback>& /*callback*/) { ndk::ScopedAStatus Vibrator::compose(const std::vector<CompositeEffect>& /*composite*/,
const std::shared_ptr<IVibratorCallback>& /*callback*/) {
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
} }
@ -184,7 +190,8 @@ ndk::ScopedAStatus Vibrator::getSupportedAlwaysOnEffects(std::vector<Effect>* /*
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); 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); return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
} }
@ -224,7 +231,8 @@ ndk::ScopedAStatus Vibrator::getSupportedBraking(std::vector<Braking>* /*_aidl_r
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
} }
ndk::ScopedAStatus Vibrator::composePwle(const std::vector<PrimitivePwle>& /*composite*/, const std::shared_ptr<IVibratorCallback>& /*callback*/) { ndk::ScopedAStatus Vibrator::composePwle(const std::vector<PrimitivePwle>& /*composite*/,
const std::shared_ptr<IVibratorCallback>& /*callback*/) {
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
} }

View file

@ -15,12 +15,12 @@
#define VIBRATOR_TIMEOUT_PATH "/sys/class/timed_output/vibrator/enable" #define VIBRATOR_TIMEOUT_PATH "/sys/class/timed_output/vibrator/enable"
#define VIBRATOR_INTENSITY_PATH "/sys/class/timed_output/vibrator/intensity" #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::Braking;
using ::aidl::android::hardware::vibrator::Effect;
using ::aidl::android::hardware::vibrator::EffectStrength;
using ::aidl::android::hardware::vibrator::CompositeEffect; using ::aidl::android::hardware::vibrator::CompositeEffect;
using ::aidl::android::hardware::vibrator::CompositePrimitive; 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; using ::aidl::android::hardware::vibrator::PrimitivePwle;
namespace aidl { namespace aidl {
@ -33,16 +33,22 @@ public:
Vibrator(); Vibrator();
ndk::ScopedAStatus getCapabilities(int32_t* _aidl_return) override; ndk::ScopedAStatus getCapabilities(int32_t* _aidl_return) override;
ndk::ScopedAStatus off() override; ndk::ScopedAStatus off() override;
ndk::ScopedAStatus on(int32_t timeoutMs, const std::shared_ptr<IVibratorCallback>& callback) override; ndk::ScopedAStatus on(int32_t timeoutMs,
ndk::ScopedAStatus perform(Effect effect, EffectStrength strength, const std::shared_ptr<IVibratorCallback>& callback, int32_t* _aidl_return) override; const std::shared_ptr<IVibratorCallback>& callback) override;
ndk::ScopedAStatus perform(Effect effect, EffectStrength strength,
const std::shared_ptr<IVibratorCallback>& callback,
int32_t* _aidl_return) override;
ndk::ScopedAStatus getSupportedEffects(std::vector<Effect>* _aidl_return) override; ndk::ScopedAStatus getSupportedEffects(std::vector<Effect>* _aidl_return) override;
ndk::ScopedAStatus setAmplitude(float amplitude) override; ndk::ScopedAStatus setAmplitude(float amplitude) override;
ndk::ScopedAStatus setExternalControl(bool enabled) override; ndk::ScopedAStatus setExternalControl(bool enabled) override;
ndk::ScopedAStatus getCompositionDelayMax(int32_t* _aidl_return) override; ndk::ScopedAStatus getCompositionDelayMax(int32_t* _aidl_return) override;
ndk::ScopedAStatus getCompositionSizeMax(int32_t* _aidl_return) override; ndk::ScopedAStatus getCompositionSizeMax(int32_t* _aidl_return) override;
ndk::ScopedAStatus getSupportedPrimitives(std::vector<CompositePrimitive>* _aidl_return) override; ndk::ScopedAStatus getSupportedPrimitives(
ndk::ScopedAStatus getPrimitiveDuration(CompositePrimitive primitive, int32_t* _aidl_return) override; std::vector<CompositePrimitive>* _aidl_return) override;
ndk::ScopedAStatus compose(const std::vector<CompositeEffect>& composite, const std::shared_ptr<IVibratorCallback>& callback) override; ndk::ScopedAStatus getPrimitiveDuration(CompositePrimitive primitive,
int32_t* _aidl_return) override;
ndk::ScopedAStatus compose(const std::vector<CompositeEffect>& composite,
const std::shared_ptr<IVibratorCallback>& callback) override;
ndk::ScopedAStatus getSupportedAlwaysOnEffects(std::vector<Effect>* _aidl_return) override; ndk::ScopedAStatus getSupportedAlwaysOnEffects(std::vector<Effect>* _aidl_return) override;
ndk::ScopedAStatus alwaysOnEnable(int32_t id, Effect effect, EffectStrength strength) override; ndk::ScopedAStatus alwaysOnEnable(int32_t id, Effect effect, EffectStrength strength) override;
ndk::ScopedAStatus alwaysOnDisable(int32_t id) override; ndk::ScopedAStatus alwaysOnDisable(int32_t id) override;
@ -54,7 +60,8 @@ public:
ndk::ScopedAStatus getPwlePrimitiveDurationMax(int32_t* _aidl_return) override; ndk::ScopedAStatus getPwlePrimitiveDurationMax(int32_t* _aidl_return) override;
ndk::ScopedAStatus getPwleCompositionSizeMax(int32_t* _aidl_return) override; ndk::ScopedAStatus getPwleCompositionSizeMax(int32_t* _aidl_return) override;
ndk::ScopedAStatus getSupportedBraking(std::vector<Braking>* _aidl_return) override; ndk::ScopedAStatus getSupportedBraking(std::vector<Braking>* _aidl_return) override;
ndk::ScopedAStatus composePwle(const std::vector<PrimitivePwle>& composite, const std::shared_ptr<IVibratorCallback>& callback) override; ndk::ScopedAStatus composePwle(const std::vector<PrimitivePwle>& composite,
const std::shared_ptr<IVibratorCallback>& callback) override;
private: private:
ndk::ScopedAStatus activate(uint32_t ms); ndk::ScopedAStatus activate(uint32_t ms);

View file

@ -6,9 +6,9 @@
#include "Vibrator.h" #include "Vibrator.h"
#include <android-base/logging.h>
#include <android/binder_manager.h> #include <android/binder_manager.h>
#include <android/binder_process.h> #include <android/binder_process.h>
#include <android-base/logging.h>
using ::aidl::android::hardware::vibrator::Vibrator; using ::aidl::android::hardware::vibrator::Vibrator;
@ -17,7 +17,8 @@ int main() {
std::shared_ptr<Vibrator> vibrator = ndk::SharedRefBase::make<Vibrator>(); std::shared_ptr<Vibrator> vibrator = ndk::SharedRefBase::make<Vibrator>();
const std::string instance = std::string() + Vibrator::descriptor + "/default"; 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); CHECK(status == STATUS_OK);
ABinderProcess_joinThreadPool(); ABinderProcess_joinThreadPool();

View file

@ -1,19 +1,19 @@
#include <vendor/eureka/hardware/battery/1.0/IBattery.h>
#include <hidl/Status.h>
#include <hidl/LegacySupport.h>
#include <hardware/hardware.h> #include <hardware/hardware.h>
#include <hidl/HidlSupport.h> #include <hidl/HidlSupport.h>
#include <hidl/LegacySupport.h>
#include <hidl/Status.h>
#include <vendor/eureka/hardware/battery/1.0/IBattery.h>
#include "jni.h" #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; using android::sp;
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 extern "C" JNIEXPORT void JNICALL
JNICALL Java_com_eurekateam_samsungextras_interfaces_Battery_setChargeSysfs(JNIEnv* env,
Java_com_eurekateam_samsungextras_interfaces_Battery_setChargeSysfs __unused jclass obj,
(JNIEnv *env , __unused jclass obj, jint enable) { jint enable) {
android::sp<IBattery> service = IBattery::getService(); android::sp<IBattery> service = IBattery::getService();
if (enable == 1) { if (enable == 1) {
service->setBatteryWritable(SysfsType::CHARGE, Number::ENABLE); service->setBatteryWritable(SysfsType::CHARGE, Number::ENABLE);
@ -22,18 +22,17 @@ Java_com_eurekateam_samsungextras_interfaces_Battery_setChargeSysfs
} }
} }
extern "C" JNIEXPORT jint extern "C" JNIEXPORT jint JNICALL
JNICALL Java_com_eurekateam_samsungextras_interfaces_Battery_getChargeSysfs(JNIEnv* env,
Java_com_eurekateam_samsungextras_interfaces_Battery_getChargeSysfs __unused jclass obj) {
(JNIEnv *env , __unused jclass obj) {
android::sp<IBattery> service = IBattery::getService(); android::sp<IBattery> service = IBattery::getService();
int ret = service->getBatteryStats(SysfsType::CHARGE); int ret = service->getBatteryStats(SysfsType::CHARGE);
return ret; return ret;
} }
extern "C" extern "C" JNIEXPORT void JNICALL
JNIEXPORT void JNICALL Java_com_eurekateam_samsungextras_interfaces_Battery_setFastCharge(JNIEnv* env,
Java_com_eurekateam_samsungextras_interfaces_Battery_setFastCharge(JNIEnv *env, __unused jobject obj, __unused jobject obj,
jint enable) { jint enable) {
android::sp<IBattery> service = IBattery::getService(); android::sp<IBattery> service = IBattery::getService();
if (enable == 1) { if (enable == 1) {
@ -42,17 +41,17 @@ Java_com_eurekateam_samsungextras_interfaces_Battery_setFastCharge(JNIEnv *env,
service->setBatteryWritable(SysfsType::FASTCHARGE, Number::DISABLE); service->setBatteryWritable(SysfsType::FASTCHARGE, Number::DISABLE);
} }
} }
extern "C" extern "C" JNIEXPORT jint JNICALL
JNIEXPORT jint JNICALL Java_com_eurekateam_samsungextras_interfaces_Battery_getFastChargeSysfs(JNIEnv* env,
Java_com_eurekateam_samsungextras_interfaces_Battery_getFastChargeSysfs(JNIEnv *env, __unused __unused jclass obj) {
jclass obj) {
android::sp<IBattery> service = IBattery::getService(); android::sp<IBattery> service = IBattery::getService();
int ret = service->getBatteryStats(SysfsType::FASTCHARGE); int ret = service->getBatteryStats(SysfsType::FASTCHARGE);
return ret; return ret;
} }
extern "C" extern "C" JNIEXPORT jint JNICALL
JNIEXPORT jint JNICALL Java_com_eurekateam_samsungextras_interfaces_Battery_getGeneralBatteryStats(JNIEnv* env,
Java_com_eurekateam_samsungextras_interfaces_Battery_getGeneralBatteryStats(JNIEnv *env,__unused jobject obj, jint id) { __unused jobject obj,
jint id) {
/** /**
* id: * id:
* 1 = BATTERY_CAPACITY_MAX * 1 = BATTERY_CAPACITY_MAX
@ -93,6 +92,4 @@ Java_com_eurekateam_samsungextras_interfaces_Battery_getGeneralBatteryStats(JNIE
break; break;
} }
return ret; return ret;
} }

View file

@ -1,20 +1,18 @@
#include <vendor/eureka/hardware/flashlight/1.0/IFlashlight.h>
#include <hidl/Status.h>
#include <hidl/LegacySupport.h>
#include <hardware/hardware.h> #include <hardware/hardware.h>
#include <hidl/HidlSupport.h> #include <hidl/HidlSupport.h>
#include <hidl/LegacySupport.h>
#include <hidl/Status.h>
#include <vendor/eureka/hardware/flashlight/1.0/IFlashlight.h>
#include "jni.h" #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::Device;
using vendor::eureka::hardware::flashlight::V1_0::Enable; 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 vendor::eureka::hardware::flashlight::V1_0::Number;
using android::sp;
extern "C" extern "C" JNIEXPORT void JNICALL Java_com_eurekateam_samsungextras_interfaces_Flashlight_setFlash(
JNIEXPORT void JNICALL JNIEnv* env, __unused jobject obj, jint value) {
Java_com_eurekateam_samsungextras_interfaces_Flashlight_setFlash(JNIEnv *env, __unused jobject obj,
jint value) {
android::sp<IFlashlight> service = IFlashlight::getService(); android::sp<IFlashlight> service = IFlashlight::getService();
service->setFlashlightEnable(Enable::ENABLE); service->setFlashlightEnable(Enable::ENABLE);
switch (value) { switch (value) {
@ -50,13 +48,10 @@ Java_com_eurekateam_samsungextras_interfaces_Flashlight_setFlash(JNIEnv *env, __
break; break;
default: default:
break; break;
} }
} }
extern "C" extern "C" JNIEXPORT jint JNICALL Java_com_eurekateam_samsungextras_interfaces_Flashlight_getFlash(
JNIEXPORT jint JNICALL JNIEnv* env, jobject clazz, jint isA10) {
Java_com_eurekateam_samsungextras_interfaces_Flashlight_getFlash(JNIEnv *env, jobject clazz,
jint isA10) {
android::sp<IFlashlight> service = IFlashlight::getService(); android::sp<IFlashlight> service = IFlashlight::getService();
int ret; int ret;
if (isA10 == 1) { if (isA10 == 1) {

View file

@ -1,16 +1,15 @@
#include <vendor/eureka/hardware/gpu/1.0/IGpu.h>
#include <hidl/Status.h>
#include <hidl/LegacySupport.h>
#include <hardware/hardware.h> #include <hardware/hardware.h>
#include <hidl/HidlSupport.h> #include <hidl/HidlSupport.h>
#include <hidl/LegacySupport.h>
#include <hidl/Status.h>
#include <vendor/eureka/hardware/gpu/1.0/IGpu.h>
#include "jni.h" #include "jni.h"
using vendor::eureka::hardware::gpu::V1_0::IGpu;
using vendor::eureka::hardware::gpu::V1_0::Enable;
using android::sp; using android::sp;
using vendor::eureka::hardware::gpu::V1_0::Enable;
using vendor::eureka::hardware::gpu::V1_0::IGpu;
extern "C" extern "C" JNIEXPORT void JNICALL
JNIEXPORT void JNICALL
Java_com_eurekateam_samsungextras_interfaces_GPU_setGPU(JNIEnv* env, jclass clazz, jint enable) { Java_com_eurekateam_samsungextras_interfaces_GPU_setGPU(JNIEnv* env, jclass clazz, jint enable) {
android::sp<IGpu> service = IGpu::getService(); android::sp<IGpu> service = IGpu::getService();
if (enable == 1) { if (enable == 1) {
@ -19,8 +18,7 @@ Java_com_eurekateam_samsungextras_interfaces_GPU_setGPU(JNIEnv *env, jclass claz
service->setGpuWritable(Enable::DISABLE); service->setGpuWritable(Enable::DISABLE);
} }
} }
extern "C" extern "C" JNIEXPORT jint JNICALL
JNIEXPORT jint JNICALL
Java_com_eurekateam_samsungextras_interfaces_GPU_getGPU(JNIEnv* env, jclass clazz) { Java_com_eurekateam_samsungextras_interfaces_GPU_getGPU(JNIEnv* env, jclass clazz) {
android::sp<IGpu> service = IGpu::getService(); android::sp<IGpu> service = IGpu::getService();
int ret = service->readGpustats(); int ret = service->readGpustats();

View file

@ -1,16 +1,15 @@
#include <vendor/eureka/security/selinux/1.0/ISELinux.h>
#include <hidl/Status.h>
#include <hidl/LegacySupport.h>
#include <hardware/hardware.h> #include <hardware/hardware.h>
#include <hidl/HidlSupport.h> #include <hidl/HidlSupport.h>
#include <hidl/LegacySupport.h>
#include <hidl/Status.h>
#include <vendor/eureka/security/selinux/1.0/ISELinux.h>
#include "jni.h" #include "jni.h"
using vendor::eureka::security::selinux::V1_0::ISELinux;
using vendor::eureka::security::selinux::V1_0::Enable;
using android::sp; using android::sp;
using vendor::eureka::security::selinux::V1_0::Enable;
using vendor::eureka::security::selinux::V1_0::ISELinux;
extern "C" extern "C" JNIEXPORT jint JNICALL
JNIEXPORT jint JNICALL
Java_com_eurekateam_samsungextras_interfaces_SELinux_getSELinux(JNIEnv* env, jclass clazz) { Java_com_eurekateam_samsungextras_interfaces_SELinux_getSELinux(JNIEnv* env, jclass clazz) {
android::sp<ISELinux> service = ISELinux::getService(); android::sp<ISELinux> service = ISELinux::getService();
int ret = service->readSELinuxstats(); int ret = service->readSELinuxstats();

View file

@ -6,21 +6,15 @@
#include <cutils/properties.h> #include <cutils/properties.h>
#include <string.h> #include <string.h>
static inline const char* BtmGetDefaultName() static inline const char* BtmGetDefaultName() {
{
char product_device[PROPERTY_VALUE_MAX]; char product_device[PROPERTY_VALUE_MAX];
property_get("ro.product.device", product_device, ""); property_get("ro.product.device", product_device, "");
if (strstr(product_device, "a10")) if (strstr(product_device, "a10")) return "Galaxy A10";
return "Galaxy A10"; if (strstr(product_device, "a20e")) return "Galaxy A20e";
if (strstr(product_device, "a20e")) if (strstr(product_device, "a20")) return "Galaxy A20";
return "Galaxy A20e"; if (strstr(product_device, "a30")) return "Galaxy A30";
if (strstr(product_device, "a20")) if (strstr(product_device, "a40")) return "Galaxy A40";
return "Galaxy A20";
if (strstr(product_device, "a30"))
return "Galaxy A30";
if (strstr(product_device, "a40"))
return "Galaxy A40";
// Fallback to Generic // Fallback to Generic
return "Samsung Galaxy"; return "Samsung Galaxy";
} }

View file

@ -24,9 +24,9 @@
#include "BiometricsFingerprint.h" #include "BiometricsFingerprint.h"
#include <dlfcn.h> #include <dlfcn.h>
#include <fstream>
#include <inttypes.h> #include <inttypes.h>
#include <unistd.h> #include <unistd.h>
#include <fstream>
#ifdef HAS_FINGERPRINT_GESTURES #ifdef HAS_FINGERPRINT_GESTURES
#include <fcntl.h> #include <fcntl.h>
@ -58,8 +58,7 @@ BiometricsFingerprint::BiometricsFingerprint() : mClientCallback(nullptr) {
return; return;
} }
int err = ioctl(uinputFd, UI_SET_EVBIT, EV_KEY) | int err = ioctl(uinputFd, UI_SET_EVBIT, EV_KEY) | ioctl(uinputFd, UI_SET_KEYBIT, KEY_UP) |
ioctl(uinputFd, UI_SET_KEYBIT, KEY_UP) |
ioctl(uinputFd, UI_SET_KEYBIT, KEY_DOWN); ioctl(uinputFd, UI_SET_KEYBIT, KEY_DOWN);
if (err != 0) { if (err != 0) {
LOG(ERROR) << "Unable to enable key events"; LOG(ERROR) << "Unable to enable key events";
@ -286,8 +285,8 @@ bool BiometricsFingerprint::openHal() {
if (handle) { if (handle) {
int err; int err;
ss_fingerprint_close = ss_fingerprint_close = reinterpret_cast<typeof(ss_fingerprint_close)>(
reinterpret_cast<typeof(ss_fingerprint_close)>(dlsym(handle, "ss_fingerprint_close")); dlsym(handle, "ss_fingerprint_close"));
ss_fingerprint_open = ss_fingerprint_open =
reinterpret_cast<typeof(ss_fingerprint_open)>(dlsym(handle, "ss_fingerprint_open")); reinterpret_cast<typeof(ss_fingerprint_open)>(dlsym(handle, "ss_fingerprint_open"));
@ -295,18 +294,18 @@ bool BiometricsFingerprint::openHal() {
dlsym(handle, "ss_set_notify_callback")); dlsym(handle, "ss_set_notify_callback"));
ss_fingerprint_pre_enroll = reinterpret_cast<typeof(ss_fingerprint_pre_enroll)>( ss_fingerprint_pre_enroll = reinterpret_cast<typeof(ss_fingerprint_pre_enroll)>(
dlsym(handle, "ss_fingerprint_pre_enroll")); dlsym(handle, "ss_fingerprint_pre_enroll"));
ss_fingerprint_enroll = ss_fingerprint_enroll = reinterpret_cast<typeof(ss_fingerprint_enroll)>(
reinterpret_cast<typeof(ss_fingerprint_enroll)>(dlsym(handle, "ss_fingerprint_enroll")); dlsym(handle, "ss_fingerprint_enroll"));
ss_fingerprint_post_enroll = reinterpret_cast<typeof(ss_fingerprint_post_enroll)>( ss_fingerprint_post_enroll = reinterpret_cast<typeof(ss_fingerprint_post_enroll)>(
dlsym(handle, "ss_fingerprint_post_enroll")); dlsym(handle, "ss_fingerprint_post_enroll"));
ss_fingerprint_get_auth_id = reinterpret_cast<typeof(ss_fingerprint_get_auth_id)>( ss_fingerprint_get_auth_id = reinterpret_cast<typeof(ss_fingerprint_get_auth_id)>(
dlsym(handle, "ss_fingerprint_get_auth_id")); dlsym(handle, "ss_fingerprint_get_auth_id"));
ss_fingerprint_cancel = ss_fingerprint_cancel = reinterpret_cast<typeof(ss_fingerprint_cancel)>(
reinterpret_cast<typeof(ss_fingerprint_cancel)>(dlsym(handle, "ss_fingerprint_cancel")); dlsym(handle, "ss_fingerprint_cancel"));
ss_fingerprint_enumerate = reinterpret_cast<typeof(ss_fingerprint_enumerate)>( ss_fingerprint_enumerate = reinterpret_cast<typeof(ss_fingerprint_enumerate)>(
dlsym(handle, "ss_fingerprint_enumerate")); dlsym(handle, "ss_fingerprint_enumerate"));
ss_fingerprint_remove = ss_fingerprint_remove = reinterpret_cast<typeof(ss_fingerprint_remove)>(
reinterpret_cast<typeof(ss_fingerprint_remove)>(dlsym(handle, "ss_fingerprint_remove")); dlsym(handle, "ss_fingerprint_remove"));
ss_fingerprint_set_active_group = reinterpret_cast<typeof(ss_fingerprint_set_active_group)>( ss_fingerprint_set_active_group = reinterpret_cast<typeof(ss_fingerprint_set_active_group)>(
dlsym(handle, "ss_fingerprint_set_active_group")); dlsym(handle, "ss_fingerprint_set_active_group"));
ss_fingerprint_authenticate = reinterpret_cast<typeof(ss_fingerprint_authenticate)>( ss_fingerprint_authenticate = reinterpret_cast<typeof(ss_fingerprint_authenticate)>(
@ -376,7 +375,8 @@ void BiometricsFingerprint::notify(const fingerprint_msg_t* msg) {
<< ", rem=" << msg->data.enroll.samples_remaining << ")"; << ", rem=" << msg->data.enroll.samples_remaining << ")";
if (!thisPtr->mClientCallback if (!thisPtr->mClientCallback
->onEnrollResult(devId, msg->data.enroll.finger.fid, ->onEnrollResult(devId, msg->data.enroll.finger.fid,
msg->data.enroll.finger.gid, msg->data.enroll.samples_remaining) msg->data.enroll.finger.gid,
msg->data.enroll.samples_remaining)
.isOk()) { .isOk()) {
LOG(ERROR) << "failed to invoke fingerprint onEnrollResult callback"; LOG(ERROR) << "failed to invoke fingerprint onEnrollResult callback";
} }
@ -386,7 +386,8 @@ void BiometricsFingerprint::notify(const fingerprint_msg_t* msg) {
<< ", gid=" << msg->data.removed.finger.gid << ", gid=" << msg->data.removed.finger.gid
<< ", rem=" << msg->data.removed.remaining_templates << ")"; << ", rem=" << msg->data.removed.remaining_templates << ")";
if (!thisPtr->mClientCallback if (!thisPtr->mClientCallback
->onRemoved(devId, msg->data.removed.finger.fid, msg->data.removed.finger.gid, ->onRemoved(devId, msg->data.removed.finger.fid,
msg->data.removed.finger.gid,
msg->data.removed.remaining_templates) msg->data.removed.remaining_templates)
.isOk()) { .isOk()) {
LOG(ERROR) << "failed to invoke fingerprint onRemoved callback"; LOG(ERROR) << "failed to invoke fingerprint onRemoved callback";
@ -409,7 +410,8 @@ void BiometricsFingerprint::notify(const fingerprint_msg_t* msg) {
// Not a recognized fingerprint // Not a recognized fingerprint
if (!thisPtr->mClientCallback if (!thisPtr->mClientCallback
->onAuthenticated(devId, msg->data.authenticated.finger.fid, ->onAuthenticated(devId, msg->data.authenticated.finger.fid,
msg->data.authenticated.finger.gid, hidl_vec<uint8_t>()) msg->data.authenticated.finger.gid,
hidl_vec<uint8_t>())
.isOk()) { .isOk()) {
LOG(ERROR) << "failed to invoke fingerprint onAuthenticated callback"; LOG(ERROR) << "failed to invoke fingerprint onAuthenticated callback";
} }
@ -436,8 +438,7 @@ void BiometricsFingerprint::handleEvent(int eventCode) {
case SEM_FINGERPRINT_EVENT_GESTURE_SWIPE_DOWN: case SEM_FINGERPRINT_EVENT_GESTURE_SWIPE_DOWN:
case SEM_FINGERPRINT_EVENT_GESTURE_SWIPE_UP: case SEM_FINGERPRINT_EVENT_GESTURE_SWIPE_UP:
struct input_event event {}; struct input_event event {};
int keycode = eventCode == SEM_FINGERPRINT_EVENT_GESTURE_SWIPE_UP ? int keycode = eventCode == SEM_FINGERPRINT_EVENT_GESTURE_SWIPE_UP ? KEY_UP : KEY_DOWN;
KEY_UP : KEY_DOWN;
int err; int err;
// Report the key // Report the key
@ -496,8 +497,8 @@ int BiometricsFingerprint::waitForSensor(std::chrono::milliseconds pollWait,
int sensorStatus = SEM_SENSOR_STATUS_WORKING; int sensorStatus = SEM_SENSOR_STATUS_WORKING;
std::chrono::milliseconds timeWaited = 0ms; std::chrono::milliseconds timeWaited = 0ms;
while (sensorStatus != SEM_SENSOR_STATUS_OK) { while (sensorStatus != SEM_SENSOR_STATUS_OK) {
if (sensorStatus == SEM_SENSOR_STATUS_CALIBRATION_ERROR if (sensorStatus == SEM_SENSOR_STATUS_CALIBRATION_ERROR ||
|| sensorStatus == SEM_SENSOR_STATUS_ERROR){ sensorStatus == SEM_SENSOR_STATUS_ERROR) {
return -1; return -1;
} }
if (timeWaited >= timeOut) { if (timeWaited >= timeOut) {

View file

@ -24,12 +24,12 @@
#include <linux/uinput.h> #include <linux/uinput.h>
#endif #endif
#include <android/hardware/biometrics/fingerprint/2.1/types.h>
#include <android/hardware/biometrics/fingerprint/2.3/IBiometricsFingerprint.h>
#include <hardware/fingerprint.h> #include <hardware/fingerprint.h>
#include <hardware/hardware.h> #include <hardware/hardware.h>
#include <hidl/MQDescriptor.h> #include <hidl/MQDescriptor.h>
#include <hidl/Status.h> #include <hidl/Status.h>
#include <android/hardware/biometrics/fingerprint/2.3/IBiometricsFingerprint.h>
#include <android/hardware/biometrics/fingerprint/2.1/types.h>
#include "VendorConstants.h" #include "VendorConstants.h"
@ -47,11 +47,11 @@ using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec; using ::android::hardware::hidl_vec;
using ::android::hardware::Return; using ::android::hardware::Return;
using ::android::hardware::Void; 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::FingerprintAcquiredInfo;
using ::android::hardware::biometrics::fingerprint::V2_1::FingerprintError; 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_1::RequestStatus;
using ::android::hardware::biometrics::fingerprint::V2_3::IBiometricsFingerprint;
struct BiometricsFingerprint : public IBiometricsFingerprint { struct BiometricsFingerprint : public IBiometricsFingerprint {
BiometricsFingerprint(); BiometricsFingerprint();
@ -60,7 +60,8 @@ struct BiometricsFingerprint : public IBiometricsFingerprint {
// Method to wrap legacy HAL with BiometricsFingerprint class // Method to wrap legacy HAL with BiometricsFingerprint class
static IBiometricsFingerprint* getInstance(); static IBiometricsFingerprint* getInstance();
// Methods from ::android::hardware::biometrics::fingerprint::V2_3::IBiometricsFingerprint follow. // Methods from ::android::hardware::biometrics::fingerprint::V2_3::IBiometricsFingerprint
// follow.
Return<uint64_t> setNotify( Return<uint64_t> setNotify(
const sp<IBiometricsFingerprintClientCallback>& clientCallback) override; const sp<IBiometricsFingerprintClientCallback>& clientCallback) override;
Return<uint64_t> preEnroll() override; Return<uint64_t> preEnroll() override;
@ -111,7 +112,8 @@ struct BiometricsFingerprint : public IBiometricsFingerprint {
int (*ss_fingerprint_remove)(uint32_t gid, uint32_t fid); 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_set_active_group)(uint32_t gid, const char* store_path);
int (*ss_fingerprint_authenticate)(uint64_t operation_id, uint32_t gid); 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 } // namespace implementation

View file

@ -55,28 +55,20 @@ static Result ResultFromStatus(status_t err) {
} }
} }
Sensors::Sensors() Sensors::Sensors() : mInitCheck(NO_INIT), mSensorModule(nullptr), mSensorDevice(nullptr) {
: mInitCheck(NO_INIT),
mSensorModule(nullptr),
mSensorDevice(nullptr) {
status_t err = OK; status_t err = OK;
if (UseMultiHal()) { if (UseMultiHal()) {
mSensorModule = ::get_multi_hal_module_info(); mSensorModule = ::get_multi_hal_module_info();
} else { } else {
err = hw_get_module( err = hw_get_module(SENSORS_HARDWARE_MODULE_ID, (hw_module_t const**)&mSensorModule);
SENSORS_HARDWARE_MODULE_ID,
(hw_module_t const **)&mSensorModule);
} }
if (mSensorModule == NULL) { if (mSensorModule == NULL) {
err = UNKNOWN_ERROR; err = UNKNOWN_ERROR;
} }
if (err != OK) { if (err != OK) {
LOG(ERROR) << "Couldn't load " LOG(ERROR) << "Couldn't load " << SENSORS_HARDWARE_MODULE_ID << " module ("
<< SENSORS_HARDWARE_MODULE_ID << strerror(-err) << ")";
<< " module ("
<< strerror(-err)
<< ")";
mInitCheck = err; mInitCheck = err;
return; return;
@ -85,11 +77,8 @@ Sensors::Sensors()
err = sensors_open_1(&mSensorModule->common, &mSensorDevice); err = sensors_open_1(&mSensorModule->common, &mSensorDevice);
if (err != OK) { if (err != OK) {
LOG(ERROR) << "Couldn't open device for module " LOG(ERROR) << "Couldn't open device for module " << SENSORS_HARDWARE_MODULE_ID << " ("
<< SENSORS_HARDWARE_MODULE_ID << strerror(-err) << ")";
<< " ("
<< strerror(-err)
<< ")";
mInitCheck = err; mInitCheck = err;
return; return;
@ -166,24 +155,19 @@ int Sensors::getHalDeviceVersion() const {
} }
Return<Result> Sensors::setOperationMode(OperationMode mode) { Return<Result> Sensors::setOperationMode(OperationMode mode) {
if (getHalDeviceVersion() < SENSORS_DEVICE_API_VERSION_1_4 if (getHalDeviceVersion() < SENSORS_DEVICE_API_VERSION_1_4 ||
|| mSensorModule->set_operation_mode == nullptr) { mSensorModule->set_operation_mode == nullptr) {
return Result::INVALID_OPERATION; return Result::INVALID_OPERATION;
} }
return ResultFromStatus(mSensorModule->set_operation_mode((uint32_t)mode)); return ResultFromStatus(mSensorModule->set_operation_mode((uint32_t)mode));
} }
Return<Result> Sensors::activate( Return<Result> Sensors::activate(int32_t sensor_handle, bool enabled) {
int32_t sensor_handle, bool enabled) { return ResultFromStatus(mSensorDevice->activate(
return ResultFromStatus( reinterpret_cast<sensors_poll_device_t*>(mSensorDevice), sensor_handle, enabled));
mSensorDevice->activate(
reinterpret_cast<sensors_poll_device_t *>(mSensorDevice),
sensor_handle,
enabled));
} }
Return<void> Sensors::poll(int32_t maxCount, poll_cb _hidl_cb) { Return<void> Sensors::poll(int32_t maxCount, poll_cb _hidl_cb) {
hidl_vec<Event> out; hidl_vec<Event> out;
hidl_vec<SensorInfo> dynamicSensorsAdded; hidl_vec<SensorInfo> dynamicSensorsAdded;
@ -203,8 +187,8 @@ Return<void> Sensors::poll(int32_t maxCount, poll_cb _hidl_cb) {
if (!lock.owns_lock()) { if (!lock.owns_lock()) {
// cannot get the lock, hidl service will go into deadlock if it is not restarted. // cannot get the lock, hidl service will go into deadlock if it is not restarted.
// This is guaranteed to not trigger in passthrough mode. // This is guaranteed to not trigger in passthrough mode.
LOG(ERROR) << LOG(ERROR)
"ISensors::poll() re-entry. I do not know what to do except killing myself."; << "ISensors::poll() re-entry. I do not know what to do except killing myself.";
::exit(-1); ::exit(-1);
} }
@ -213,8 +197,7 @@ Return<void> Sensors::poll(int32_t maxCount, poll_cb _hidl_cb) {
} else { } else {
int bufferSize = maxCount <= kPollMaxBufferSize ? maxCount : kPollMaxBufferSize; int bufferSize = maxCount <= kPollMaxBufferSize ? maxCount : kPollMaxBufferSize;
data.reset(new sensors_event_t[bufferSize]); data.reset(new sensors_event_t[bufferSize]);
err = mSensorDevice->poll( err = mSensorDevice->poll(reinterpret_cast<sensors_poll_device_t*>(mSensorDevice),
reinterpret_cast<sensors_poll_device_t *>(mSensorDevice),
data.get(), bufferSize); data.get(), bufferSize);
} }
} }
@ -256,17 +239,10 @@ Return<void> Sensors::poll(int32_t maxCount, poll_cb _hidl_cb) {
return Void(); return Void();
} }
Return<Result> Sensors::batch( Return<Result> Sensors::batch(int32_t sensor_handle, int64_t sampling_period_ns,
int32_t sensor_handle,
int64_t sampling_period_ns,
int64_t max_report_latency_ns) { int64_t max_report_latency_ns) {
return ResultFromStatus( return ResultFromStatus(mSensorDevice->batch(mSensorDevice, sensor_handle, 0, /*flags*/
mSensorDevice->batch( sampling_period_ns, max_report_latency_ns));
mSensorDevice,
sensor_handle,
0, /*flags*/
sampling_period_ns,
max_report_latency_ns));
} }
Return<Result> Sensors::flush(int32_t sensor_handle) { Return<Result> Sensors::flush(int32_t sensor_handle) {
@ -274,22 +250,21 @@ Return<Result> Sensors::flush(int32_t sensor_handle) {
} }
Return<Result> Sensors::injectSensorData(const Event& event) { Return<Result> Sensors::injectSensorData(const Event& event) {
if (getHalDeviceVersion() < SENSORS_DEVICE_API_VERSION_1_4 if (getHalDeviceVersion() < SENSORS_DEVICE_API_VERSION_1_4 ||
|| mSensorDevice->inject_sensor_data == nullptr) { mSensorDevice->inject_sensor_data == nullptr) {
return Result::INVALID_OPERATION; return Result::INVALID_OPERATION;
} }
sensors_event_t out; sensors_event_t out;
convertToSensorEvent(event, &out); convertToSensorEvent(event, &out);
return ResultFromStatus( return ResultFromStatus(mSensorDevice->inject_sensor_data(mSensorDevice, &out));
mSensorDevice->inject_sensor_data(mSensorDevice, &out));
} }
Return<void> Sensors::registerDirectChannel( Return<void> Sensors::registerDirectChannel(const SharedMemInfo& mem,
const SharedMemInfo& mem, registerDirectChannel_cb _hidl_cb) { registerDirectChannel_cb _hidl_cb) {
if (mSensorDevice->register_direct_channel == nullptr if (mSensorDevice->register_direct_channel == nullptr ||
|| mSensorDevice->config_direct_report == nullptr) { mSensorDevice->config_direct_report == nullptr) {
// HAL does not support // HAL does not support
_hidl_cb(Result::INVALID_OPERATION, -1); _hidl_cb(Result::INVALID_OPERATION, -1);
return Void(); return Void();
@ -313,8 +288,8 @@ Return<void> Sensors::registerDirectChannel(
} }
Return<Result> Sensors::unregisterDirectChannel(int32_t channelHandle) { Return<Result> Sensors::unregisterDirectChannel(int32_t channelHandle) {
if (mSensorDevice->register_direct_channel == nullptr if (mSensorDevice->register_direct_channel == nullptr ||
|| mSensorDevice->config_direct_report == nullptr) { mSensorDevice->config_direct_report == nullptr) {
// HAL does not support // HAL does not support
return Result::INVALID_OPERATION; return Result::INVALID_OPERATION;
} }
@ -324,26 +299,22 @@ Return<Result> Sensors::unregisterDirectChannel(int32_t channelHandle) {
return Result::OK; return Result::OK;
} }
Return<void> Sensors::configDirectReport( Return<void> Sensors::configDirectReport(int32_t sensorHandle, int32_t channelHandle,
int32_t sensorHandle, int32_t channelHandle, RateLevel rate, RateLevel rate, configDirectReport_cb _hidl_cb) {
configDirectReport_cb _hidl_cb) { if (mSensorDevice->register_direct_channel == nullptr ||
if (mSensorDevice->register_direct_channel == nullptr mSensorDevice->config_direct_report == nullptr) {
|| mSensorDevice->config_direct_report == nullptr) {
// HAL does not support // HAL does not support
_hidl_cb(Result::INVALID_OPERATION, -1); _hidl_cb(Result::INVALID_OPERATION, -1);
return Void(); return Void();
} }
sensors_direct_cfg_t cfg = { sensors_direct_cfg_t cfg = {.rate_level = convertFromRateLevel(rate)};
.rate_level = convertFromRateLevel(rate)
};
if (cfg.rate_level < 0) { if (cfg.rate_level < 0) {
_hidl_cb(Result::BAD_VALUE, -1); _hidl_cb(Result::BAD_VALUE, -1);
return Void(); return Void();
} }
int err = mSensorDevice->config_direct_report(mSensorDevice, int err = mSensorDevice->config_direct_report(mSensorDevice, sensorHandle, channelHandle, &cfg);
sensorHandle, channelHandle, &cfg);
if (rate == RateLevel::STOP) { if (rate == RateLevel::STOP) {
_hidl_cb(ResultFromStatus(err), -1); _hidl_cb(ResultFromStatus(err), -1);
@ -354,9 +325,7 @@ Return<void> Sensors::configDirectReport(
} }
// static // static
void Sensors::convertFromSensorEvents( void Sensors::convertFromSensorEvents(size_t count, const sensors_event_t* srcArray,
size_t count,
const sensors_event_t *srcArray,
hidl_vec<Event>* dstVec) { hidl_vec<Event>* dstVec) {
for (size_t i = 0; i < count; ++i) { for (size_t i = 0; i < count; ++i) {
const sensors_event_t& src = srcArray[i]; const sensors_event_t& src = srcArray[i];

View file

@ -29,7 +29,6 @@ namespace sensors {
namespace V1_0 { namespace V1_0 {
namespace implementation { namespace implementation {
struct Sensors : public ::android::hardware::sensors::V1_0::ISensors { struct Sensors : public ::android::hardware::sensors::V1_0::ISensors {
Sensors(); Sensors();
@ -39,27 +38,23 @@ struct Sensors : public ::android::hardware::sensors::V1_0::ISensors {
Return<Result> setOperationMode(OperationMode mode) override; Return<Result> setOperationMode(OperationMode mode) override;
Return<Result> activate( Return<Result> activate(int32_t sensor_handle, bool enabled) override;
int32_t sensor_handle, bool enabled) override;
Return<void> poll(int32_t maxCount, poll_cb _hidl_cb) override; Return<void> poll(int32_t maxCount, poll_cb _hidl_cb) override;
Return<Result> batch( Return<Result> batch(int32_t sensor_handle, int64_t sampling_period_ns,
int32_t sensor_handle,
int64_t sampling_period_ns,
int64_t max_report_latency_ns) override; int64_t max_report_latency_ns) override;
Return<Result> flush(int32_t sensor_handle) override; Return<Result> flush(int32_t sensor_handle) override;
Return<Result> injectSensorData(const Event& event) override; Return<Result> injectSensorData(const Event& event) override;
Return<void> registerDirectChannel( Return<void> registerDirectChannel(const SharedMemInfo& mem,
const SharedMemInfo& mem, registerDirectChannel_cb _hidl_cb) override; registerDirectChannel_cb _hidl_cb) override;
Return<Result> unregisterDirectChannel(int32_t channelHandle) override; Return<Result> unregisterDirectChannel(int32_t channelHandle) override;
Return<void> configDirectReport( Return<void> configDirectReport(int32_t sensorHandle, int32_t channelHandle, RateLevel rate,
int32_t sensorHandle, int32_t channelHandle, RateLevel rate,
configDirectReport_cb _hidl_cb) override; configDirectReport_cb _hidl_cb) override;
private: private:
@ -71,8 +66,8 @@ private:
int getHalDeviceVersion() const; int getHalDeviceVersion() const;
static void convertFromSensorEvents( static void convertFromSensorEvents(size_t count, const sensors_event_t* src,
size_t count, const sensors_event_t *src, hidl_vec<Event> *dst); hidl_vec<Event>* dst);
DISALLOW_COPY_AND_ASSIGN(Sensors); DISALLOW_COPY_AND_ASSIGN(Sensors);
}; };

View file

@ -30,8 +30,8 @@
#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ #define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
#include <sys/_system_properties.h> #include <sys/_system_properties.h>
#include <android-base/properties.h>
#include <android-base/logging.h> #include <android-base/logging.h>
#include <android-base/properties.h>
#include "property_service.h" #include "property_service.h"
#include "vendor_init.h" #include "vendor_init.h"
@ -40,12 +40,7 @@ using android::base::GetProperty;
using std::string; using std::string;
std::vector<std::string> ro_props_default_source_order = { std::vector<std::string> 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) { void property_override(char const prop[], char const value[], bool add = true) {
@ -73,7 +68,8 @@ 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()) { if (fullString.length() >= ending.length()) {
return (0 == fullString.compare (fullString.length() - ending.length(), ending.length(), ending)); return (0 ==
fullString.compare(fullString.length() - ending.length(), ending.length(), ending));
} else { } else {
return false; return false;
} }
@ -87,7 +83,8 @@ void vendor_load_properties() {
model = GetProperty("ro.boot.em.model", ""); model = GetProperty("ro.boot.em.model", "");
} }
if (hasEnding(model, "N") || hasEnding(model, "S") || hasEnding(model, "K") || model == "SM-A202F") { if (hasEnding(model, "N") || hasEnding(model, "S") || hasEnding(model, "K") ||
model == "SM-A202F") {
property_override("ro.boot.product.hardware.sku", "NFC"); property_override("ro.boot.product.hardware.sku", "NFC");
} }

View file

@ -13,10 +13,10 @@
// limitations under the License. // limitations under the License.
#include "Battery.h" #include "Battery.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <unistd.h> #include <unistd.h>
#include <fstream>
#include <iostream>
#include <sstream>
namespace vendor::eureka::hardware::battery::V1_0 { namespace vendor::eureka::hardware::battery::V1_0 {
@ -60,7 +60,8 @@ Return<int32_t> Battery::getBatteryStats(battery::V1_0::SysfsType stats) {
return -1; return -1;
} }
Return<int32_t> Battery::setBatteryWritable(battery::V1_0::SysfsType stats, battery::V1_0::Number value) { Return<int32_t> Battery::setBatteryWritable(battery::V1_0::SysfsType stats,
battery::V1_0::Number value) {
std::ofstream file; std::ofstream file;
std::string filename; std::string filename;
bool FastCharge = false; bool FastCharge = false;
@ -105,4 +106,4 @@ Return<int32_t> Battery::setBatteryWritable(battery::V1_0::SysfsType stats, batt
IBattery* Battery::getInstance(void) { IBattery* Battery::getInstance(void) {
return new Battery(); return new Battery();
} }
} // namespace android::hardware::battery::implementation } // namespace vendor::eureka::hardware::battery::V1_0

View file

@ -14,22 +14,22 @@
#pragma once #pragma once
#include <vendor/eureka/hardware/battery/1.0/IBattery.h>
#include <hidl/MQDescriptor.h> #include <hidl/MQDescriptor.h>
#include <hidl/Status.h> #include <hidl/Status.h>
#include <vendor/eureka/hardware/battery/1.0/IBattery.h>
#define ANDROID_SYSTEM_UID 1000 #define ANDROID_SYSTEM_UID 1000
#define ANDROID_ROOT_UID 0 #define ANDROID_ROOT_UID 0
namespace vendor::eureka::hardware::battery::V1_0 { namespace vendor::eureka::hardware::battery::V1_0 {
using ::android::sp;
using ::android::hardware::hidl_array; using ::android::hardware::hidl_array;
using ::android::hardware::hidl_memory; using ::android::hardware::hidl_memory;
using ::android::hardware::hidl_string; using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec; using ::android::hardware::hidl_vec;
using ::android::hardware::Return; using ::android::hardware::Return;
using ::android::hardware::Void; using ::android::hardware::Void;
using ::android::sp;
struct Battery : public IBattery { struct Battery : public IBattery {
// Methods from ::vendor::eureka::hardware::battery::V1_0::IBattery follow. // 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. // Methods from ::android::hidl::base::V1_0::IBase follow.
static IBattery* getInstance(void); static IBattery* getInstance(void);
}; };
} // namespace android::hardware::battery::implementation } // namespace vendor::eureka::hardware::battery::V1_0

View file

@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#define LOG_TAG "vendor.eureka.hardware.battery@1.0-service" #define LOG_TAG "vendor.eureka.hardware.battery@1.0-service"
#include <vendor/eureka/hardware/battery/1.0/IBattery.h> #include <vendor/eureka/hardware/battery/1.0/IBattery.h>
@ -21,11 +20,11 @@
#include "Battery.h" #include "Battery.h"
using vendor::eureka::hardware::battery::V1_0::IBattery; using android::sp;
using vendor::eureka::hardware::battery::V1_0::Battery;
using android::hardware::configureRpcThreadpool; using android::hardware::configureRpcThreadpool;
using android::hardware::joinRpcThreadpool; 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 main() {
int ret; int ret;

View file

@ -13,8 +13,8 @@
// limitations under the License. // limitations under the License.
#include "Flashlight.h" #include "Flashlight.h"
#include <iostream>
#include <fstream> #include <fstream>
#include <iostream>
#include <sstream> #include <sstream>
namespace vendor::eureka::hardware::flashlight::V1_0 { namespace vendor::eureka::hardware::flashlight::V1_0 {
@ -107,4 +107,4 @@ Return<int32_t> Flashlight::readFlashlightstats(flashlight::V1_0::Device device)
IFlashlight* Flashlight::getInstance(void) { IFlashlight* Flashlight::getInstance(void) {
return new Flashlight(); return new Flashlight();
} }
} // namespace android::hardware::flashlight::implementation } // namespace vendor::eureka::hardware::flashlight::V1_0

View file

@ -14,19 +14,19 @@
#pragma once #pragma once
#include <vendor/eureka/hardware/flashlight/1.0/IFlashlight.h>
#include <hidl/MQDescriptor.h> #include <hidl/MQDescriptor.h>
#include <hidl/Status.h> #include <hidl/Status.h>
#include <vendor/eureka/hardware/flashlight/1.0/IFlashlight.h>
namespace vendor::eureka::hardware::flashlight::V1_0 { namespace vendor::eureka::hardware::flashlight::V1_0 {
using ::android::sp;
using ::android::hardware::hidl_array; using ::android::hardware::hidl_array;
using ::android::hardware::hidl_memory; using ::android::hardware::hidl_memory;
using ::android::hardware::hidl_string; using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec; using ::android::hardware::hidl_vec;
using ::android::hardware::Return; using ::android::hardware::Return;
using ::android::hardware::Void; using ::android::hardware::Void;
using ::android::sp;
struct Flashlight : public IFlashlight { struct Flashlight : public IFlashlight {
// Methods from ::vendor::eureka::hardware::flashlight::V1_0::IFlashlight follow. // Methods from ::vendor::eureka::hardware::flashlight::V1_0::IFlashlight follow.
@ -35,6 +35,5 @@ struct Flashlight : public IFlashlight {
Return<int32_t> readFlashlightstats(Device device); Return<int32_t> readFlashlightstats(Device device);
// Methods from ::android::hidl::base::V1_0::IBase follow. // Methods from ::android::hidl::base::V1_0::IBase follow.
static IFlashlight* getInstance(void); static IFlashlight* getInstance(void);
}; };
} // namespace android::hardware::flashlight::implementation } // namespace vendor::eureka::hardware::flashlight::V1_0

View file

@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#define LOG_TAG "vendor.eureka.hardware.flashlight@1.0-service" #define LOG_TAG "vendor.eureka.hardware.flashlight@1.0-service"
#include <vendor/eureka/hardware/flashlight/1.0/IFlashlight.h> #include <vendor/eureka/hardware/flashlight/1.0/IFlashlight.h>
@ -21,11 +20,11 @@
#include "Flashlight.h" #include "Flashlight.h"
using vendor::eureka::hardware::flashlight::V1_0::IFlashlight; using android::sp;
using vendor::eureka::hardware::flashlight::V1_0::Flashlight;
using android::hardware::configureRpcThreadpool; using android::hardware::configureRpcThreadpool;
using android::hardware::joinRpcThreadpool; 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 main() {
int ret; int ret;

View file

@ -13,8 +13,8 @@
// limitations under the License. // limitations under the License.
#include "Gpu.h" #include "Gpu.h"
#include <iostream>
#include <fstream> #include <fstream>
#include <iostream>
#include <sstream> #include <sstream>
namespace vendor::eureka::hardware::gpu::V1_0 { namespace vendor::eureka::hardware::gpu::V1_0 {
@ -50,4 +50,4 @@ Return<int32_t> Gpu::readGpustats(void) {
IGpu* Gpu::getInstance(void) { IGpu* Gpu::getInstance(void) {
return new Gpu(); return new Gpu();
} }
} // namespace android::hardware::gpu::implementation } // namespace vendor::eureka::hardware::gpu::V1_0

View file

@ -14,19 +14,19 @@
#pragma once #pragma once
#include <vendor/eureka/hardware/gpu/1.0/IGpu.h>
#include <hidl/MQDescriptor.h> #include <hidl/MQDescriptor.h>
#include <hidl/Status.h> #include <hidl/Status.h>
#include <vendor/eureka/hardware/gpu/1.0/IGpu.h>
namespace vendor::eureka::hardware::gpu::V1_0 { namespace vendor::eureka::hardware::gpu::V1_0 {
using ::android::sp;
using ::android::hardware::hidl_array; using ::android::hardware::hidl_array;
using ::android::hardware::hidl_memory; using ::android::hardware::hidl_memory;
using ::android::hardware::hidl_string; using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec; using ::android::hardware::hidl_vec;
using ::android::hardware::Return; using ::android::hardware::Return;
using ::android::hardware::Void; using ::android::hardware::Void;
using ::android::sp;
struct Gpu : public IGpu { struct Gpu : public IGpu {
// Methods from ::vendor::eureka::hardware::gpu::V1_0::IGpu follow. // Methods from ::vendor::eureka::hardware::gpu::V1_0::IGpu follow.
@ -34,6 +34,5 @@ struct Gpu : public IGpu {
Return<int32_t> readGpustats(void); Return<int32_t> readGpustats(void);
// Methods from ::android::hidl::base::V1_0::IBase follow. // Methods from ::android::hidl::base::V1_0::IBase follow.
static IGpu* getInstance(void); static IGpu* getInstance(void);
}; };
} // namespace android::hardware::gpu::implementation } // namespace vendor::eureka::hardware::gpu::V1_0

View file

@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#define LOG_TAG "vendor.eureka.hardware.gpu@1.0-service" #define LOG_TAG "vendor.eureka.hardware.gpu@1.0-service"
#include <vendor/eureka/hardware/gpu/1.0/IGpu.h> #include <vendor/eureka/hardware/gpu/1.0/IGpu.h>
@ -21,11 +20,11 @@
#include "Gpu.h" #include "Gpu.h"
using vendor::eureka::hardware::gpu::V1_0::IGpu; using android::sp;
using vendor::eureka::hardware::gpu::V1_0::Gpu;
using android::hardware::configureRpcThreadpool; using android::hardware::configureRpcThreadpool;
using android::hardware::joinRpcThreadpool; 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 main() {
int ret; int ret;

View file

@ -13,8 +13,8 @@
// limitations under the License. // limitations under the License.
#include "SELinux.h" #include "SELinux.h"
#include <iostream>
#include <fstream> #include <fstream>
#include <iostream>
#include <sstream> #include <sstream>
namespace vendor::eureka::security::selinux::V1_0 { namespace vendor::eureka::security::selinux::V1_0 {
@ -50,4 +50,4 @@ Return<int32_t> SELinux::readSELinuxstats(void) {
ISELinux* SELinux::getInstance(void) { ISELinux* SELinux::getInstance(void) {
return new SELinux(); return new SELinux();
} }
} // namespace android::security::selinux::implementation } // namespace vendor::eureka::security::selinux::V1_0

View file

@ -14,19 +14,19 @@
#pragma once #pragma once
#include <vendor/eureka/security/selinux/1.0/ISELinux.h>
#include <hidl/MQDescriptor.h> #include <hidl/MQDescriptor.h>
#include <hidl/Status.h> #include <hidl/Status.h>
#include <vendor/eureka/security/selinux/1.0/ISELinux.h>
namespace vendor::eureka::security::selinux::V1_0 { namespace vendor::eureka::security::selinux::V1_0 {
using ::android::sp;
using ::android::hardware::hidl_array; using ::android::hardware::hidl_array;
using ::android::hardware::hidl_memory; using ::android::hardware::hidl_memory;
using ::android::hardware::hidl_string; using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec; using ::android::hardware::hidl_vec;
using ::android::hardware::Return; using ::android::hardware::Return;
using ::android::hardware::Void; using ::android::hardware::Void;
using ::android::sp;
struct SELinux : public ISELinux { struct SELinux : public ISELinux {
// Methods from ::vendor::eureka::security::selinux::V1_0::ISELinux follow. // Methods from ::vendor::eureka::security::selinux::V1_0::ISELinux follow.
@ -34,6 +34,5 @@ struct SELinux : public ISELinux {
Return<int32_t> readSELinuxstats(void); Return<int32_t> readSELinuxstats(void);
// Methods from ::android::hidl::base::V1_0::IBase follow. // Methods from ::android::hidl::base::V1_0::IBase follow.
static ISELinux* getInstance(void); static ISELinux* getInstance(void);
}; };
} // namespace android::security::selinux::implementation } // namespace vendor::eureka::security::selinux::V1_0

View file

@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#define LOG_TAG "vendor.eureka.security.selinux@1.0-service" #define LOG_TAG "vendor.eureka.security.selinux@1.0-service"
#include <vendor/eureka/security/selinux/1.0/ISELinux.h> #include <vendor/eureka/security/selinux/1.0/ISELinux.h>
@ -21,11 +20,11 @@
#include "SELinux.h" #include "SELinux.h"
using vendor::eureka::security::selinux::V1_0::ISELinux; using android::sp;
using vendor::eureka::security::selinux::V1_0::SELinux;
using android::hardware::configureRpcThreadpool; using android::hardware::configureRpcThreadpool;
using android::hardware::joinRpcThreadpool; 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 main() {
int ret; int ret;

View file

@ -24,26 +24,19 @@
namespace android { namespace android {
#define ALIGN_TO(val, alignment) \ #define ALIGN_TO(val, alignment) (((uintptr_t)(val) + ((alignment)-1)) & ~((alignment)-1))
(((uintptr_t)(val) + ((alignment) - 1)) & ~((alignment) - 1))
CameraMetadata::CameraMetadata() : CameraMetadata::CameraMetadata() : mBuffer(NULL), mLocked(false) {}
mBuffer(NULL), mLocked(false) {
}
CameraMetadata::CameraMetadata(size_t entryCapacity, size_t dataCapacity) : CameraMetadata::CameraMetadata(size_t entryCapacity, size_t dataCapacity) : mLocked(false) {
mLocked(false)
{
mBuffer = allocate_camera_metadata(entryCapacity, dataCapacity); mBuffer = allocate_camera_metadata(entryCapacity, dataCapacity);
} }
CameraMetadata::CameraMetadata(const CameraMetadata &other) : CameraMetadata::CameraMetadata(const CameraMetadata& other) : mLocked(false) {
mLocked(false) {
mBuffer = clone_camera_metadata(other.mBuffer); mBuffer = clone_camera_metadata(other.mBuffer);
} }
CameraMetadata::CameraMetadata(camera_metadata_t *buffer) : CameraMetadata::CameraMetadata(camera_metadata_t* buffer) : mBuffer(NULL), mLocked(false) {
mBuffer(NULL), mLocked(false) {
acquire(buffer); acquire(buffer);
} }
@ -81,8 +74,7 @@ status_t CameraMetadata::unlock(const camera_metadata_t *buffer) const {
return INVALID_OPERATION; return INVALID_OPERATION;
} }
if (buffer != mBuffer) { if (buffer != mBuffer) {
ALOGE("%s: Can't unlock CameraMetadata with wrong pointer!", ALOGE("%s: Can't unlock CameraMetadata with wrong pointer!", __FUNCTION__);
__FUNCTION__);
return BAD_VALUE; return BAD_VALUE;
} }
mLocked = false; mLocked = false;
@ -119,8 +111,7 @@ void CameraMetadata::acquire(camera_metadata_t *buffer) {
mBuffer = buffer; mBuffer = buffer;
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 %p", "%s: Failed to validate metadata structure %p", __FUNCTION__, buffer);
__FUNCTION__, buffer);
} }
void CameraMetadata::acquire(CameraMetadata& other) { void CameraMetadata::acquire(CameraMetadata& other) {
@ -148,8 +139,7 @@ status_t CameraMetadata::append(const camera_metadata_t* other) {
} }
size_t CameraMetadata::entryCount() const { size_t CameraMetadata::entryCount() const {
return (mBuffer == NULL) ? 0 : return (mBuffer == NULL) ? 0 : get_camera_metadata_entry_count(mBuffer);
get_camera_metadata_entry_count(mBuffer);
} }
bool CameraMetadata::isEmpty() const { bool CameraMetadata::isEmpty() const {
@ -174,15 +164,13 @@ status_t CameraMetadata::checkType(uint32_t tag, uint8_t expectedType) {
ALOGE("Mismatched tag type when updating entry %s (%d) of type %s; " ALOGE("Mismatched tag type when updating entry %s (%d) of type %s; "
"got type %s data instead ", "got type %s data instead ",
get_local_camera_metadata_tag_name(tag, mBuffer), tag, get_local_camera_metadata_tag_name(tag, mBuffer), tag,
camera_metadata_type_names[tagType], camera_metadata_type_names[tagType], camera_metadata_type_names[expectedType]);
camera_metadata_type_names[expectedType]);
return INVALID_OPERATION; return INVALID_OPERATION;
} }
return OK; return OK;
} }
status_t CameraMetadata::update(uint32_t tag, status_t CameraMetadata::update(uint32_t tag, const int32_t* data, size_t data_count) {
const int32_t *data, size_t data_count) {
status_t res; status_t res;
if (mLocked) { if (mLocked) {
ALOGE("%s: CameraMetadata is locked", __FUNCTION__); ALOGE("%s: CameraMetadata is locked", __FUNCTION__);
@ -194,8 +182,7 @@ status_t CameraMetadata::update(uint32_t tag,
return updateImpl(tag, (const void*)data, data_count); return updateImpl(tag, (const void*)data, data_count);
} }
status_t CameraMetadata::update(uint32_t tag, status_t CameraMetadata::update(uint32_t tag, const uint8_t* data, size_t data_count) {
const uint8_t *data, size_t data_count) {
status_t res; status_t res;
if (mLocked) { if (mLocked) {
ALOGE("%s: CameraMetadata is locked", __FUNCTION__); ALOGE("%s: CameraMetadata is locked", __FUNCTION__);
@ -207,8 +194,7 @@ status_t CameraMetadata::update(uint32_t tag,
return updateImpl(tag, (const void*)data, data_count); return updateImpl(tag, (const void*)data, data_count);
} }
status_t CameraMetadata::update(uint32_t tag, status_t CameraMetadata::update(uint32_t tag, const float* data, size_t data_count) {
const float *data, size_t data_count) {
status_t res; status_t res;
if (mLocked) { if (mLocked) {
ALOGE("%s: CameraMetadata is locked", __FUNCTION__); ALOGE("%s: CameraMetadata is locked", __FUNCTION__);
@ -220,8 +206,7 @@ status_t CameraMetadata::update(uint32_t tag,
return updateImpl(tag, (const void*)data, data_count); return updateImpl(tag, (const void*)data, data_count);
} }
status_t CameraMetadata::update(uint32_t tag, status_t CameraMetadata::update(uint32_t tag, const int64_t* data, size_t data_count) {
const int64_t *data, size_t data_count) {
status_t res; status_t res;
if (mLocked) { if (mLocked) {
ALOGE("%s: CameraMetadata is locked", __FUNCTION__); ALOGE("%s: CameraMetadata is locked", __FUNCTION__);
@ -233,8 +218,7 @@ status_t CameraMetadata::update(uint32_t tag,
return updateImpl(tag, (const void*)data, data_count); return updateImpl(tag, (const void*)data, data_count);
} }
status_t CameraMetadata::update(uint32_t tag, status_t CameraMetadata::update(uint32_t tag, const double* data, size_t data_count) {
const double *data, size_t data_count) {
status_t res; status_t res;
if (mLocked) { if (mLocked) {
ALOGE("%s: CameraMetadata is locked", __FUNCTION__); ALOGE("%s: CameraMetadata is locked", __FUNCTION__);
@ -246,8 +230,8 @@ status_t CameraMetadata::update(uint32_t tag,
return updateImpl(tag, (const void*)data, data_count); return updateImpl(tag, (const void*)data, data_count);
} }
status_t CameraMetadata::update(uint32_t tag, status_t CameraMetadata::update(uint32_t tag, const camera_metadata_rational_t* data,
const camera_metadata_rational_t *data, size_t data_count) { size_t data_count) {
status_t res; status_t res;
if (mLocked) { if (mLocked) {
ALOGE("%s: CameraMetadata is locked", __FUNCTION__); ALOGE("%s: CameraMetadata is locked", __FUNCTION__);
@ -259,8 +243,7 @@ status_t CameraMetadata::update(uint32_t tag,
return updateImpl(tag, (const void*)data, data_count); return updateImpl(tag, (const void*)data, data_count);
} }
status_t CameraMetadata::update(uint32_t tag, status_t CameraMetadata::update(uint32_t tag, const String8& string) {
const String8 &string) {
status_t res; status_t res;
if (mLocked) { if (mLocked) {
ALOGE("%s: CameraMetadata is locked", __FUNCTION__); ALOGE("%s: CameraMetadata is locked", __FUNCTION__);
@ -285,8 +268,7 @@ status_t CameraMetadata::update(const camera_metadata_ro_entry &entry) {
return updateImpl(entry.tag, (const void*)entry.data.u8, entry.count); return updateImpl(entry.tag, (const void*)entry.data.u8, entry.count);
} }
status_t CameraMetadata::updateImpl(uint32_t tag, const void *data, status_t CameraMetadata::updateImpl(uint32_t tag, const void* data, size_t data_count) {
size_t data_count) {
status_t res; status_t res;
if (mLocked) { if (mLocked) {
ALOGE("%s: CameraMetadata is locked", __FUNCTION__); 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<uintptr_t>(mBuffer); uintptr_t bufAddr = reinterpret_cast<uintptr_t>(mBuffer);
uintptr_t dataAddr = reinterpret_cast<uintptr_t>(data); uintptr_t dataAddr = reinterpret_cast<uintptr_t>(data);
if (dataAddr > bufAddr && dataAddr < (bufAddr + bufferSize)) { if (dataAddr > bufAddr && dataAddr < (bufAddr + bufferSize)) {
ALOGE("%s: Update attempted with data from the same metadata buffer!", ALOGE("%s: Update attempted with data from the same metadata buffer!", __FUNCTION__);
__FUNCTION__);
return INVALID_OPERATION; return INVALID_OPERATION;
} }
size_t data_size = calculate_camera_metadata_entry_data_size(type, size_t data_size = calculate_camera_metadata_entry_data_size(type, data_count);
data_count);
res = resizeIfNeeded(1, data_size); res = resizeIfNeeded(1, data_size);
@ -317,27 +297,23 @@ status_t CameraMetadata::updateImpl(uint32_t tag, const void *data,
camera_metadata_entry_t entry; camera_metadata_entry_t entry;
res = find_camera_metadata_entry(mBuffer, tag, &entry); res = find_camera_metadata_entry(mBuffer, tag, &entry);
if (res == NAME_NOT_FOUND) { if (res == NAME_NOT_FOUND) {
res = add_camera_metadata_entry(mBuffer, res = add_camera_metadata_entry(mBuffer, tag, data, data_count);
tag, data, data_count);
} else if (res == OK) { } else if (res == OK) {
res = update_camera_metadata_entry(mBuffer, res = update_camera_metadata_entry(mBuffer, entry.index, data, data_count, NULL);
entry.index, data, data_count, NULL);
} }
} }
if (res != OK) { if (res != OK) {
ALOGE("%s: Unable to update metadata entry %s.%s (%x): %s (%d)", ALOGE("%s: Unable to update metadata entry %s.%s (%x): %s (%d)", __FUNCTION__,
__FUNCTION__, get_local_camera_metadata_section_name(tag, mBuffer), get_local_camera_metadata_section_name(tag, mBuffer),
get_local_camera_metadata_tag_name(tag, mBuffer), tag, get_local_camera_metadata_tag_name(tag, mBuffer), tag, strerror(-res), res);
strerror(-res), res);
} }
IF_ALOGV() { IF_ALOGV() {
ALOGE_IF(validate_camera_metadata_structure(mBuffer, /*size*/NULL) != ALOGE_IF(validate_camera_metadata_structure(mBuffer, /*size*/ NULL) != OK,
OK,
"%s: Failed to validate metadata structure after update %p", "%s: Failed to validate metadata structure after update %p", __FUNCTION__,
__FUNCTION__, mBuffer); mBuffer);
} }
return res; return res;
@ -386,20 +362,16 @@ status_t CameraMetadata::erase(uint32_t tag) {
if (res == NAME_NOT_FOUND) { if (res == NAME_NOT_FOUND) {
return OK; return OK;
} else if (res != OK) { } else if (res != OK) {
ALOGE("%s: Error looking for entry %s.%s (%x): %s %d", ALOGE("%s: Error looking for entry %s.%s (%x): %s %d", __FUNCTION__,
__FUNCTION__,
get_local_camera_metadata_section_name(tag, mBuffer), get_local_camera_metadata_section_name(tag, mBuffer),
get_local_camera_metadata_tag_name(tag, mBuffer), get_local_camera_metadata_tag_name(tag, mBuffer), tag, strerror(-res), res);
tag, strerror(-res), res);
return res; return res;
} }
res = delete_camera_metadata_entry(mBuffer, entry.index); res = delete_camera_metadata_entry(mBuffer, entry.index);
if (res != OK) { if (res != OK) {
ALOGE("%s: Error deleting entry %s.%s (%x): %s %d", ALOGE("%s: Error deleting entry %s.%s (%x): %s %d", __FUNCTION__,
__FUNCTION__,
get_local_camera_metadata_section_name(tag, mBuffer), get_local_camera_metadata_section_name(tag, mBuffer),
get_local_camera_metadata_tag_name(tag, mBuffer), get_local_camera_metadata_tag_name(tag, mBuffer), tag, strerror(-res), res);
tag, strerror(-res), res);
} }
return res; return res;
} }
@ -418,23 +390,17 @@ status_t CameraMetadata::resizeIfNeeded(size_t extraEntries, size_t extraData) {
} else { } else {
size_t currentEntryCount = get_camera_metadata_entry_count(mBuffer); size_t currentEntryCount = get_camera_metadata_entry_count(mBuffer);
size_t currentEntryCap = get_camera_metadata_entry_capacity(mBuffer); size_t currentEntryCap = get_camera_metadata_entry_capacity(mBuffer);
size_t newEntryCount = currentEntryCount + size_t newEntryCount = currentEntryCount + extraEntries;
extraEntries; newEntryCount = (newEntryCount > currentEntryCap) ? newEntryCount * 2 : currentEntryCap;
newEntryCount = (newEntryCount > currentEntryCap) ?
newEntryCount * 2 : currentEntryCap;
size_t currentDataCount = get_camera_metadata_data_count(mBuffer); size_t currentDataCount = get_camera_metadata_data_count(mBuffer);
size_t currentDataCap = get_camera_metadata_data_capacity(mBuffer); size_t currentDataCap = get_camera_metadata_data_capacity(mBuffer);
size_t newDataCount = currentDataCount + size_t newDataCount = currentDataCount + extraData;
extraData; newDataCount = (newDataCount > currentDataCap) ? newDataCount * 2 : currentDataCap;
newDataCount = (newDataCount > currentDataCap) ?
newDataCount * 2 : currentDataCap;
if (newEntryCount > currentEntryCap || if (newEntryCount > currentEntryCap || newDataCount > currentDataCap) {
newDataCount > currentDataCap) {
camera_metadata_t* oldBuffer = mBuffer; camera_metadata_t* oldBuffer = mBuffer;
mBuffer = allocate_camera_metadata(newEntryCount, mBuffer = allocate_camera_metadata(newEntryCount, newDataCount);
newDataCount);
if (mBuffer == NULL) { if (mBuffer == NULL) {
ALOGE("%s: Can't allocate larger metadata buffer", __FUNCTION__); ALOGE("%s: Can't allocate larger metadata buffer", __FUNCTION__);
return NO_MEMORY; return NO_MEMORY;
@ -462,5 +428,4 @@ void CameraMetadata::swap(CameraMetadata& other) {
mBuffer = otherBuf; mBuffer = otherBuf;
} }
}; // namespace android }; // namespace android

View file

@ -123,23 +123,15 @@ class CameraMetadata {
* will reallocate the buffer if insufficient space exists. Overloaded for * will reallocate the buffer if insufficient space exists. Overloaded for
* the various types of valid data. * the various types of valid data.
*/ */
status_t update(uint32_t tag, status_t update(uint32_t tag, const uint8_t* data, size_t data_count);
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, status_t update(uint32_t tag, const float* data, size_t data_count);
const int32_t *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, status_t update(uint32_t tag, const double* data, size_t data_count);
const float *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, status_t update(uint32_t tag, const String8& string);
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(const camera_metadata_ro_entry& entry);
template <typename T> template <typename T>
status_t update(uint32_t tag, Vector<T> data) { status_t update(uint32_t tag, Vector<T> data) {
return update(tag, data.array(), data.size()); return update(tag, data.array(), data.size());
@ -202,7 +194,6 @@ class CameraMetadata {
* Resize metadata buffer if needed by reallocating it and copying it over. * Resize metadata buffer if needed by reallocating it and copying it over.
*/ */
status_t resizeIfNeeded(size_t extraEntries, size_t extraData); status_t resizeIfNeeded(size_t extraEntries, size_t extraData);
}; };
} // namespace android } // namespace android

View file

@ -18,11 +18,11 @@
#define LOG_TAG "CameraParams" #define LOG_TAG "CameraParams"
#include <log/log.h> #include <log/log.h>
#include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <system/graphics.h>
#include <unistd.h> #include <unistd.h>
#include "CameraParameters.h" #include "CameraParameters.h"
#include <system/graphics.h>
namespace android { 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[] = "auto-exposure-lock";
const char CameraParameters::KEY_AUTO_EXPOSURE_LOCK_SUPPORTED[] = "auto-exposure-lock-supported"; 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[] = "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_MAX_NUM_METERING_AREAS[] = "max-num-metering-areas";
const char CameraParameters::KEY_METERING_AREAS[] = "metering-areas"; const char CameraParameters::KEY_METERING_AREAS[] = "metering-areas";
const char CameraParameters::KEY_ZOOM[] = "zoom"; 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_FRAME_FORMAT[] = "video-frame-format";
const char CameraParameters::KEY_VIDEO_SIZE[] = "video-size"; const char CameraParameters::KEY_VIDEO_SIZE[] = "video-size";
const char CameraParameters::KEY_SUPPORTED_VIDEO_SIZES[] = "video-size-values"; 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_HW[] = "max-num-detected-faces-hw";
const char CameraParameters::KEY_MAX_NUM_DETECTED_FACES_SW[] = "max-num-detected-faces-sw"; const char CameraParameters::KEY_MAX_NUM_DETECTED_FACES_SW[] = "max-num-detected-faces-sw";
const char CameraParameters::KEY_RECORDING_HINT[] = "recording-hint"; const char CameraParameters::KEY_RECORDING_HINT[] = "recording-hint";
@ -175,17 +177,11 @@ const char CameraParameters::FOCUS_MODE_CONTINUOUS_PICTURE[] = "continuous-pictu
const char CameraParameters::LIGHTFX_LOWLIGHT[] = "low-light"; const char CameraParameters::LIGHTFX_LOWLIGHT[] = "low-light";
const char CameraParameters::LIGHTFX_HDR[] = "high-dynamic-range"; const char CameraParameters::LIGHTFX_HDR[] = "high-dynamic-range";
CameraParameters::CameraParameters() CameraParameters::CameraParameters() : mMap() {}
: mMap()
{
}
CameraParameters::~CameraParameters() CameraParameters::~CameraParameters() {}
{
}
String8 CameraParameters::flatten() const String8 CameraParameters::flatten() const {
{
String8 flattened(""); String8 flattened("");
size_t size = mMap.size(); size_t size = mMap.size();
@ -197,15 +193,13 @@ String8 CameraParameters::flatten() const
flattened += k; flattened += k;
flattened += "="; flattened += "=";
flattened += v; flattened += v;
if (i != size-1) if (i != size - 1) flattened += ";";
flattened += ";";
} }
return flattened; return flattened;
} }
void CameraParameters::unflatten(const String8 &params) void CameraParameters::unflatten(const String8& params) {
{
const char* a = params.string(); const char* a = params.string();
const char* b; const char* b;
@ -214,8 +208,7 @@ void CameraParameters::unflatten(const String8 &params)
for (;;) { for (;;) {
// Find the bounds of the key name. // Find the bounds of the key name.
b = strchr(a, '='); b = strchr(a, '=');
if (b == 0) if (b == 0) break;
break;
// Create the key string. // Create the key string.
String8 k(a, (size_t)(b - a)); String8 k(a, (size_t)(b - a));
@ -236,9 +229,7 @@ void CameraParameters::unflatten(const String8 &params)
} }
} }
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() // i think i can do this with strspn()
if (strchr(key, '=') || strchr(key, ';')) { if (strchr(key, '=') || strchr(key, ';')) {
// ALOGE("Key \"%s\"contains invalid character (= or ;)", key); // ALOGE("Key \"%s\"contains invalid character (= or ;)", key);
@ -253,52 +244,42 @@ void CameraParameters::set(const char *key, const char *value)
mMap.replaceValueFor(String8(key), String8(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]; char str[16];
sprintf(str, "%d", value); sprintf(str, "%d", value);
set(key, str); 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. char str[16]; // 14 should be enough. We overestimate to be safe.
snprintf(str, sizeof(str), "%g", value); snprintf(str, sizeof(str), "%g", value);
set(key, str); 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)); String8 v = mMap.valueFor(String8(key));
if (v.length() == 0) if (v.length() == 0) return 0;
return 0;
return v.string(); return v.string();
} }
int CameraParameters::getInt(const char *key) const int CameraParameters::getInt(const char* key) const {
{
const char* v = get(key); const char* v = get(key);
if (v == 0) if (v == 0) return -1;
return -1;
return strtol(v, 0, 0); return strtol(v, 0, 0);
} }
float CameraParameters::getFloat(const char *key) const float CameraParameters::getFloat(const char* key) const {
{
const char* v = get(key); const char* v = get(key);
if (v == 0) return -1; if (v == 0) return -1;
return strtof(v, 0); return strtof(v, 0);
} }
void CameraParameters::remove(const char *key) void CameraParameters::remove(const char* key) {
{
mMap.removeItem(String8(key)); mMap.removeItem(String8(key));
} }
// Parse string like "640x480" or "10000,20000" // Parse string like "640x480" or "10000,20000"
static int parse_pair(const char *str, int *first, int *second, char delim, static int parse_pair(const char* str, int* first, int* second, char delim, char** endptr = NULL) {
char **endptr = NULL)
{
// Find the first integer. // Find the first integer.
char* end; char* end;
int w = (int)strtol(str, &end, 10); int w = (int)strtol(str, &end, 10);
@ -321,8 +302,7 @@ static int parse_pair(const char *str, int *first, int *second, char delim,
return 0; return 0;
} }
static void parseSizesList(const char *sizesStr, Vector<Size> &sizes) static void parseSizesList(const char* sizesStr, Vector<Size>& sizes) {
{
if (sizesStr == 0) { if (sizesStr == 0) {
return; return;
} }
@ -331,8 +311,7 @@ static void parseSizesList(const char *sizesStr, Vector<Size> &sizes)
while (true) { while (true) {
int width, height; int width, height;
int success = parse_pair(sizeStartPtr, &width, &height, 'x', int success = parse_pair(sizeStartPtr, &width, &height, 'x', &sizeStartPtr);
&sizeStartPtr);
if (success == -1 || (*sizeStartPtr != ',' && *sizeStartPtr != '\0')) { if (success == -1 || (*sizeStartPtr != ',' && *sizeStartPtr != '\0')) {
ALOGE("Picture sizes string \"%s\" contains invalid character.", sizesStr); ALOGE("Picture sizes string \"%s\" contains invalid character.", sizesStr);
return; return;
@ -346,15 +325,13 @@ static void parseSizesList(const char *sizesStr, Vector<Size> &sizes)
} }
} }
void CameraParameters::setPreviewSize(int width, int height) void CameraParameters::setPreviewSize(int width, int height) {
{
char str[32]; char str[32];
sprintf(str, "%dx%d", width, height); sprintf(str, "%dx%d", width, height);
set(KEY_PREVIEW_SIZE, str); set(KEY_PREVIEW_SIZE, str);
} }
void CameraParameters::getPreviewSize(int *width, int *height) const void CameraParameters::getPreviewSize(int* width, int* height) const {
{
*width = *height = -1; *width = *height = -1;
// Get the current string, if it doesn't exist, leave the -1x-1 // Get the current string, if it doesn't exist, leave the -1x-1
const char* p = get(KEY_PREVIEW_SIZE); const char* p = get(KEY_PREVIEW_SIZE);
@ -362,78 +339,66 @@ void CameraParameters::getPreviewSize(int *width, int *height) const
parse_pair(p, width, height, 'x'); 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; *width = *height = -1;
const char* p = get(KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO); const char* p = get(KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO);
if (p == 0) return; if (p == 0) return;
parse_pair(p, width, height, 'x'); parse_pair(p, width, height, 'x');
} }
void CameraParameters::getSupportedPreviewSizes(Vector<Size> &sizes) const void CameraParameters::getSupportedPreviewSizes(Vector<Size>& sizes) const {
{
const char* previewSizesStr = get(KEY_SUPPORTED_PREVIEW_SIZES); const char* previewSizesStr = get(KEY_SUPPORTED_PREVIEW_SIZES);
parseSizesList(previewSizesStr, sizes); parseSizesList(previewSizesStr, sizes);
} }
void CameraParameters::setVideoSize(int width, int height) void CameraParameters::setVideoSize(int width, int height) {
{
char str[32]; char str[32];
sprintf(str, "%dx%d", width, height); sprintf(str, "%dx%d", width, height);
set(KEY_VIDEO_SIZE, str); set(KEY_VIDEO_SIZE, str);
} }
void CameraParameters::getVideoSize(int *width, int *height) const void CameraParameters::getVideoSize(int* width, int* height) const {
{
*width = *height = -1; *width = *height = -1;
const char* p = get(KEY_VIDEO_SIZE); const char* p = get(KEY_VIDEO_SIZE);
if (p == 0) return; if (p == 0) return;
parse_pair(p, width, height, 'x'); parse_pair(p, width, height, 'x');
} }
void CameraParameters::getSupportedVideoSizes(Vector<Size> &sizes) const void CameraParameters::getSupportedVideoSizes(Vector<Size>& sizes) const {
{
const char* videoSizesStr = get(KEY_SUPPORTED_VIDEO_SIZES); const char* videoSizesStr = get(KEY_SUPPORTED_VIDEO_SIZES);
parseSizesList(videoSizesStr, sizes); parseSizesList(videoSizesStr, sizes);
} }
void CameraParameters::setPreviewFrameRate(int fps) void CameraParameters::setPreviewFrameRate(int fps) {
{
set(KEY_PREVIEW_FRAME_RATE, fps); set(KEY_PREVIEW_FRAME_RATE, fps);
} }
int CameraParameters::getPreviewFrameRate() const int CameraParameters::getPreviewFrameRate() const {
{
return getInt(KEY_PREVIEW_FRAME_RATE); 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; *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; if (p == 0) return;
parse_pair(p, min_fps, max_fps, ','); parse_pair(p, min_fps, max_fps, ',');
} }
void CameraParameters::setPreviewFormat(const char *format) void CameraParameters::setPreviewFormat(const char* format) {
{
set(KEY_PREVIEW_FORMAT, format); set(KEY_PREVIEW_FORMAT, format);
} }
const char *CameraParameters::getPreviewFormat() const const char* CameraParameters::getPreviewFormat() const {
{
return get(KEY_PREVIEW_FORMAT); return get(KEY_PREVIEW_FORMAT);
} }
void CameraParameters::setPictureSize(int width, int height) void CameraParameters::setPictureSize(int width, int height) {
{
char str[32]; char str[32];
sprintf(str, "%dx%d", width, height); sprintf(str, "%dx%d", width, height);
set(KEY_PICTURE_SIZE, str); set(KEY_PICTURE_SIZE, str);
} }
void CameraParameters::getPictureSize(int *width, int *height) const void CameraParameters::getPictureSize(int* width, int* height) const {
{
*width = *height = -1; *width = *height = -1;
// Get the current string, if it doesn't exist, leave the -1x-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);
@ -441,24 +406,20 @@ void CameraParameters::getPictureSize(int *width, int *height) const
parse_pair(p, width, height, 'x'); parse_pair(p, width, height, 'x');
} }
void CameraParameters::getSupportedPictureSizes(Vector<Size> &sizes) const void CameraParameters::getSupportedPictureSizes(Vector<Size>& sizes) const {
{
const char* pictureSizesStr = get(KEY_SUPPORTED_PICTURE_SIZES); const char* pictureSizesStr = get(KEY_SUPPORTED_PICTURE_SIZES);
parseSizesList(pictureSizesStr, sizes); parseSizesList(pictureSizesStr, sizes);
} }
void CameraParameters::setPictureFormat(const char *format) void CameraParameters::setPictureFormat(const char* format) {
{
set(KEY_PICTURE_FORMAT, format); set(KEY_PICTURE_FORMAT, format);
} }
const char *CameraParameters::getPictureFormat() const const char* CameraParameters::getPictureFormat() const {
{
return get(KEY_PICTURE_FORMAT); return get(KEY_PICTURE_FORMAT);
} }
void CameraParameters::dump() const void CameraParameters::dump() const {
{
ALOGD("dump: mMap.size = %zu", mMap.size()); ALOGD("dump: mMap.size = %zu", mMap.size());
for (size_t i = 0; i < mMap.size(); i++) { for (size_t i = 0; i < mMap.size(); i++) {
String8 k, v; String8 k, v;
@ -468,8 +429,7 @@ void CameraParameters::dump() const
} }
} }
status_t CameraParameters::dump(int fd, const Vector<String16>& /*args*/) const status_t CameraParameters::dump(int fd, const Vector<String16>& /*args*/) const {
{
const size_t SIZE = 256; const size_t SIZE = 256;
char buffer[SIZE]; char buffer[SIZE];
String8 result; String8 result;
@ -487,8 +447,7 @@ status_t CameraParameters::dump(int fd, const Vector<String16>& /*args*/) const
} }
void CameraParameters::getSupportedPreviewFormats(Vector<int>& formats) const { void CameraParameters::getSupportedPreviewFormats(Vector<int>& formats) const {
const char* supportedPreviewFormats = const char* supportedPreviewFormats = get(CameraParameters::KEY_SUPPORTED_PREVIEW_FORMATS);
get(CameraParameters::KEY_SUPPORTED_PREVIEW_FORMATS);
if (supportedPreviewFormats == NULL) { if (supportedPreviewFormats == NULL) {
ALOGW("%s: No supported preview formats.", __FUNCTION__); ALOGW("%s: No supported preview formats.", __FUNCTION__);
@ -510,25 +469,22 @@ void CameraParameters::getSupportedPreviewFormats(Vector<int>& formats) const {
fmtStr.unlockBuffer(fmtStr.size()); fmtStr.unlockBuffer(fmtStr.size());
} }
int CameraParameters::previewFormatToEnum(const char* format) { int CameraParameters::previewFormatToEnum(const char* format) {
return return !format ? HAL_PIXEL_FORMAT_YCrCb_420_SP
!format ? : !strcmp(format, PIXEL_FORMAT_YUV422SP) ? HAL_PIXEL_FORMAT_YCbCr_422_SP
HAL_PIXEL_FORMAT_YCrCb_420_SP : : // NV16
!strcmp(format, PIXEL_FORMAT_YUV422SP) ? !strcmp(format, PIXEL_FORMAT_YUV420SP) ? HAL_PIXEL_FORMAT_YCrCb_420_SP
HAL_PIXEL_FORMAT_YCbCr_422_SP : // NV16 : // NV21
!strcmp(format, PIXEL_FORMAT_YUV420SP) ? !strcmp(format, PIXEL_FORMAT_YUV422I) ? HAL_PIXEL_FORMAT_YCbCr_422_I
HAL_PIXEL_FORMAT_YCrCb_420_SP : // NV21 : // YUY2
!strcmp(format, PIXEL_FORMAT_YUV422I) ? !strcmp(format, PIXEL_FORMAT_YUV420P) ? HAL_PIXEL_FORMAT_YV12
HAL_PIXEL_FORMAT_YCbCr_422_I : // YUY2 : // YV12
!strcmp(format, PIXEL_FORMAT_YUV420P) ? !strcmp(format, PIXEL_FORMAT_RGB565) ? HAL_PIXEL_FORMAT_RGB_565
HAL_PIXEL_FORMAT_YV12 : // YV12 : // RGB565
!strcmp(format, PIXEL_FORMAT_RGB565) ? !strcmp(format, PIXEL_FORMAT_RGBA8888) ? HAL_PIXEL_FORMAT_RGBA_8888
HAL_PIXEL_FORMAT_RGB_565 : // RGB565 : // RGB8888
!strcmp(format, PIXEL_FORMAT_RGBA8888) ? !strcmp(format, PIXEL_FORMAT_BAYER_RGGB) ? HAL_PIXEL_FORMAT_RAW16
HAL_PIXEL_FORMAT_RGBA_8888 : // RGB8888 : // Raw sensor data
!strcmp(format, PIXEL_FORMAT_BAYER_RGGB) ?
HAL_PIXEL_FORMAT_RAW16 : // Raw sensor data
-1; -1;
} }

View file

@ -37,8 +37,7 @@ struct Size {
} }
}; };
class CameraParameters class CameraParameters {
{
public: public:
CameraParameters(); CameraParameters();
CameraParameters(const String8& params) { unflatten(params); } CameraParameters(const String8& params) { unflatten(params); }
@ -694,6 +693,6 @@ private:
DefaultKeyedVector<String8, String8> mMap; DefaultKeyedVector<String8, String8> mMap;
}; };
}; // namespace }; // namespace android
#endif #endif

View file

@ -42,11 +42,8 @@ extern "C" int ALooper_release_forCamera(ALooper *sLooper) {
return 0; return 0;
} }
extern "C" int ALooper_pollOnce_camera(ALooper *sLooper, extern "C" int ALooper_pollOnce_camera(ALooper* sLooper, int timeoutMillis, int* outFd,
int timeoutMillis, int* outEvents, void** outData) {
int* outFd,
int* outEvents,
void** outData) {
int res = sLooper->pollOnce(timeoutMillis, outFd, outEvents, outData); int res = sLooper->pollOnce(timeoutMillis, outFd, outEvents, outData);
LOG(VERBOSE) << "ALooper_pollOnce_camera => " << res; LOG(VERBOSE) << "ALooper_pollOnce_camera => " << res;
return res; return res;

View file

@ -45,8 +45,7 @@ void LoadProperties(std::string data) {
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
std::string prop = FACTORY_PROP; std::string prop = FACTORY_PROP;
if (argc > 1 && std::string(argv[1]) == "NetworkConfig") if (argc > 1 && std::string(argv[1]) == "NetworkConfig") prop = TELEPHONY_PROP;
prop = TELEPHONY_PROP;
std::ifstream in(EFS_NEW + prop); std::ifstream in(EFS_NEW + prop);
if (in.good()) { if (in.good()) {

3
universal7885-common/usb/typeb/Usb.cpp Executable file → Normal file
View file

@ -51,8 +51,7 @@ Return<void> Usb::queryPortStatus() {
pthread_mutex_lock(&mLock); pthread_mutex_lock(&mLock);
if (mCallback != NULL) { if (mCallback != NULL) {
Return<void> ret = Return<void> ret = mCallback->notifyPortStatusChange(currentPortStatus, Status::SUCCESS);
mCallback->notifyPortStatusChange(currentPortStatus, Status::SUCCESS);
if (!ret.isOk()) { if (!ret.isOk()) {
LOG(ERROR) << "queryPortStatus error " << ret.description(); LOG(ERROR) << "queryPortStatus error " << ret.description();
} }

10
universal7885-common/usb/typeb/Usb.h Executable file → Normal file
View file

@ -35,17 +35,17 @@ namespace usb {
namespace V1_0 { namespace V1_0 {
namespace implementation { namespace implementation {
using ::android::hardware::usb::V1_0::IUsb; using ::android::sp;
using ::android::hardware::usb::V1_0::IUsbCallback;
using ::android::hardware::usb::V1_0::PortRole;
using ::android::hidl::base::V1_0::IBase;
using ::android::hardware::hidl_array; using ::android::hardware::hidl_array;
using ::android::hardware::hidl_memory; using ::android::hardware::hidl_memory;
using ::android::hardware::hidl_string; using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec; using ::android::hardware::hidl_vec;
using ::android::hardware::Return; using ::android::hardware::Return;
using ::android::hardware::Void; 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 { struct Usb : public IUsb {
Return<void> switchRole(const hidl_string& portName, const PortRole& role) override; Return<void> switchRole(const hidl_string& portName, const PortRole& role) override;

View file

@ -18,14 +18,14 @@
#include <android-base/logging.h> #include <android-base/logging.h>
#include <assert.h> #include <assert.h>
#include <chrono>
#include <dirent.h> #include <dirent.h>
#include <pthread.h> #include <pthread.h>
#include <regex>
#include <stdio.h> #include <stdio.h>
#include <sys/types.h> #include <sys/types.h>
#include <thread>
#include <unistd.h> #include <unistd.h>
#include <chrono>
#include <regex>
#include <thread>
#include <unordered_map> #include <unordered_map>
#include <cutils/uevent.h> #include <cutils/uevent.h>
@ -72,8 +72,7 @@ static int32_t readFile(const std::string &filename, std::string *contents) {
return -1; return -1;
} }
static int32_t writeFile(const std::string &filename, static int32_t writeFile(const std::string& filename, const std::string& contents) {
const std::string &contents) {
FILE* fp; FILE* fp;
int ret; int ret;
@ -93,8 +92,7 @@ static int32_t writeFile(const std::string &filename,
return -1; return -1;
} }
std::string appendRoleNodeHelper(const std::string &portName, std::string appendRoleNodeHelper(const std::string& portName, PortRoleType type) {
PortRoleType type) {
std::string node("/sys/class/typec/" + portName); std::string node("/sys/class/typec/" + portName);
switch (type) { switch (type) {
@ -117,8 +115,7 @@ std::string convertRoletoString(PortRole role) {
return "sink"; return "sink";
} else if (role.type == PortRoleType::DATA_ROLE) { } else if (role.type == PortRoleType::DATA_ROLE) {
if (role.role == static_cast<uint32_t>(PortDataRole::HOST)) return "host"; if (role.role == static_cast<uint32_t>(PortDataRole::HOST)) return "host";
if (role.role == static_cast<uint32_t>(PortDataRole::DEVICE)) if (role.role == static_cast<uint32_t>(PortDataRole::DEVICE)) return "device";
return "device";
} else if (role.type == PortRoleType::MODE) { } else if (role.type == PortRoleType::MODE) {
if (role.role == static_cast<uint32_t>(PortMode_1_1::UFP)) return "sink"; if (role.role == static_cast<uint32_t>(PortMode_1_1::UFP)) return "sink";
if (role.role == static_cast<uint32_t>(PortMode_1_1::DFP)) return "source"; if (role.role == static_cast<uint32_t>(PortMode_1_1::DFP)) return "source";
@ -138,8 +135,7 @@ void extractRole(std::string *roleName) {
} }
void switchToDrp(const std::string& portName) { void switchToDrp(const std::string& portName) {
std::string filename = std::string filename = appendRoleNodeHelper(std::string(portName.c_str()), PortRoleType::MODE);
appendRoleNodeHelper(std::string(portName.c_str()), PortRoleType::MODE);
FILE* fp; FILE* fp;
if (filename != "") { if (filename != "") {
@ -147,8 +143,7 @@ void switchToDrp(const std::string &portName) {
if (fp != NULL) { if (fp != NULL) {
int ret = fputs("dual", fp); int ret = fputs("dual", fp);
fclose(fp); fclose(fp);
if (ret == EOF) if (ret == EOF) ALOGE("Fatal: Error while switching back to drp");
ALOGE("Fatal: Error while switching back to drp");
} else { } else {
ALOGE("Fatal: Cannot open file to switch back to drp"); ALOGE("Fatal: Cannot open file to switch back to drp");
} }
@ -157,10 +152,8 @@ void switchToDrp(const std::string &portName) {
} }
} }
bool switchMode(const hidl_string &portName, bool switchMode(const hidl_string& portName, const PortRole& newRole, struct Usb* usb) {
const PortRole &newRole, struct Usb *usb) { std::string filename = appendRoleNodeHelper(std::string(portName.c_str()), newRole.type);
std::string filename =
appendRoleNodeHelper(std::string(portName.c_str()), newRole.type);
std::string written; std::string written;
FILE* fp; FILE* fp;
bool roleSwitch = false; bool roleSwitch = false;
@ -206,8 +199,7 @@ wait_again:
pthread_mutex_unlock(&usb->mPartnerLock); pthread_mutex_unlock(&usb->mPartnerLock);
} }
if (!roleSwitch) if (!roleSwitch) switchToDrp(std::string(portName.c_str()));
switchToDrp(std::string(portName.c_str()));
return roleSwitch; return roleSwitch;
} }
@ -236,11 +228,8 @@ Usb::Usb()
} }
} }
Return<void> Usb::switchRole(const hidl_string& portName, const PortRole& newRole) {
Return<void> Usb::switchRole(const hidl_string &portName, std::string filename = appendRoleNodeHelper(std::string(portName.c_str()), newRole.type);
const PortRole &newRole) {
std::string filename =
appendRoleNodeHelper(std::string(portName.c_str()), newRole.type);
std::string written; std::string written;
FILE* fp; FILE* fp;
bool roleSwitch = false; bool roleSwitch = false;
@ -252,8 +241,7 @@ Return<void> Usb::switchRole(const hidl_string &portName,
pthread_mutex_lock(&mRoleSwitchLock); pthread_mutex_lock(&mRoleSwitchLock);
ALOGI("filename write: %s role:%s", filename.c_str(), ALOGI("filename write: %s role:%s", filename.c_str(), convertRoletoString(newRole).c_str());
convertRoletoString(newRole).c_str());
if (newRole.type == PortRoleType::MODE) { if (newRole.type == PortRoleType::MODE) {
roleSwitch = switchMode(portName, newRole, this); roleSwitch = switchMode(portName, newRole, this);
@ -280,11 +268,9 @@ Return<void> Usb::switchRole(const hidl_string &portName,
pthread_mutex_lock(&mLock); pthread_mutex_lock(&mLock);
if (mCallback_1_0 != NULL) { if (mCallback_1_0 != NULL) {
Return<void> ret = Return<void> ret = mCallback_1_0->notifyRoleSwitchStatus(
mCallback_1_0->notifyRoleSwitchStatus(portName, newRole, portName, newRole, roleSwitch ? Status::SUCCESS : Status::ERROR);
roleSwitch ? Status::SUCCESS : Status::ERROR); if (!ret.isOk()) ALOGE("RoleSwitchStatus error %s", ret.description().c_str());
if (!ret.isOk())
ALOGE("RoleSwitchStatus error %s", ret.description().c_str());
} else { } else {
ALOGE("Not notifying the userspace. Callback is not set"); ALOGE("Not notifying the userspace. Callback is not set");
} }
@ -295,20 +281,18 @@ Return<void> Usb::switchRole(const hidl_string &portName,
} }
Status getAccessoryConnected(const std::string& portName, std::string* accessory) { Status getAccessoryConnected(const std::string& portName, std::string* accessory) {
std::string filename = std::string filename = "/sys/class/typec/" + portName + "-partner/accessory_mode";
"/sys/class/typec/" + portName + "-partner/accessory_mode";
if (readFile(filename, accessory)) { if (readFile(filename, accessory)) {
ALOGE("getAccessoryConnected: Failed to open filesystem node: %s", ALOGE("getAccessoryConnected: Failed to open filesystem node: %s", filename.c_str());
filename.c_str());
return Status::ERROR; return Status::ERROR;
} }
return Status::SUCCESS; return Status::SUCCESS;
} }
Status getCurrentRoleHelper(const std::string &portName, bool connected, Status getCurrentRoleHelper(const std::string& portName, bool connected, PortRoleType type,
PortRoleType type, uint32_t *currentRole) { uint32_t* currentRole) {
std::string filename; std::string filename;
std::string roleName; std::string roleName;
std::string accessory; std::string accessory;
@ -344,8 +328,7 @@ Status getCurrentRoleHelper(const std::string &portName, bool connected,
} }
if (readFile(filename, &roleName)) { if (readFile(filename, &roleName)) {
ALOGE("getCurrentRole: Failed to open filesystem node: %s", ALOGE("getCurrentRole: Failed to open filesystem node: %s", filename.c_str());
filename.c_str());
return Status::ERROR; return Status::ERROR;
} }
@ -404,8 +387,7 @@ Status getTypeCPortNamesHelper(std::unordered_map<std::string, bool> *names) {
} }
bool canSwitchRoleHelper(const std::string& portName, PortRoleType /*type*/) { bool canSwitchRoleHelper(const std::string& portName, PortRoleType /*type*/) {
std::string filename = std::string filename = "/sys/class/typec/" + portName + "-partner/supports_usb_power_delivery";
"/sys/class/typec/" + portName + "-partner/supports_usb_power_delivery";
std::string supportsPD; std::string supportsPD;
if (!readFile(filename, &supportsPD)) { if (!readFile(filename, &supportsPD)) {
@ -422,8 +404,7 @@ bool canSwitchRoleHelper(const std::string &portName, PortRoleType /*type*/) {
* The caller of this method would reconstruct the V1_0::PortStatus * The caller of this method would reconstruct the V1_0::PortStatus
* object if required. * object if required.
*/ */
Status getPortStatusHelper(hidl_vec<PortStatus_1_1> *currentPortStatus_1_1, Status getPortStatusHelper(hidl_vec<PortStatus_1_1>* currentPortStatus_1_1, bool V1_0) {
bool V1_0) {
std::unordered_map<std::string, bool> names; std::unordered_map<std::string, bool> names;
Status result = getTypeCPortNamesHelper(&names); Status result = getTypeCPortNamesHelper(&names);
int i = -1; int i = -1;
@ -436,8 +417,7 @@ Status getPortStatusHelper(hidl_vec<PortStatus_1_1> *currentPortStatus_1_1,
(*currentPortStatus_1_1)[i].status.portName = port.first; (*currentPortStatus_1_1)[i].status.portName = port.first;
uint32_t currentRole; uint32_t currentRole;
if (getCurrentRoleHelper(port.first, port.second, if (getCurrentRoleHelper(port.first, port.second, PortRoleType::POWER_ROLE,
PortRoleType::POWER_ROLE,
&currentRole) == Status::SUCCESS) { &currentRole) == Status::SUCCESS) {
(*currentPortStatus_1_1)[i].status.currentPowerRole = (*currentPortStatus_1_1)[i].status.currentPowerRole =
static_cast<PortPowerRole>(currentRole); static_cast<PortPowerRole>(currentRole);
@ -455,10 +435,9 @@ Status getPortStatusHelper(hidl_vec<PortStatus_1_1> *currentPortStatus_1_1,
goto done; goto done;
} }
if (getCurrentRoleHelper(port.first, port.second, PortRoleType::MODE, if (getCurrentRoleHelper(port.first, port.second, PortRoleType::MODE, &currentRole) ==
&currentRole) == Status::SUCCESS) { Status::SUCCESS) {
(*currentPortStatus_1_1)[i].currentMode = (*currentPortStatus_1_1)[i].currentMode = static_cast<PortMode_1_1>(currentRole);
static_cast<PortMode_1_1>(currentRole);
(*currentPortStatus_1_1)[i].status.currentMode = (*currentPortStatus_1_1)[i].status.currentMode =
static_cast<V1_0::PortMode>(currentRole); static_cast<V1_0::PortMode>(currentRole);
} else { } else {
@ -468,15 +447,12 @@ Status getPortStatusHelper(hidl_vec<PortStatus_1_1> *currentPortStatus_1_1,
(*currentPortStatus_1_1)[i].status.canChangeMode = true; (*currentPortStatus_1_1)[i].status.canChangeMode = true;
(*currentPortStatus_1_1)[i].status.canChangeDataRole = (*currentPortStatus_1_1)[i].status.canChangeDataRole =
port.second ? canSwitchRoleHelper(port.first, PortRoleType::DATA_ROLE) port.second ? canSwitchRoleHelper(port.first, PortRoleType::DATA_ROLE) : false;
: false;
(*currentPortStatus_1_1)[i].status.canChangePowerRole = (*currentPortStatus_1_1)[i].status.canChangePowerRole =
port.second port.second ? canSwitchRoleHelper(port.first, PortRoleType::POWER_ROLE) : false;
? canSwitchRoleHelper(port.first, PortRoleType::POWER_ROLE)
: false;
ALOGI("connected:%d canChangeMode:%d canChagedata:%d canChangePower:%d", ALOGI("connected:%d canChangeMode:%d canChagedata:%d canChangePower:%d", port.second,
port.second, (*currentPortStatus_1_1)[i].status.canChangeMode, (*currentPortStatus_1_1)[i].status.canChangeMode,
(*currentPortStatus_1_1)[i].status.canChangeDataRole, (*currentPortStatus_1_1)[i].status.canChangeDataRole,
(*currentPortStatus_1_1)[i].status.canChangePowerRole); (*currentPortStatus_1_1)[i].status.canChangePowerRole);
@ -518,8 +494,7 @@ Return<void> Usb::queryPortStatus() {
else else
ret = mCallback_1_0->notifyPortStatusChange(currentPortStatus, status); ret = mCallback_1_0->notifyPortStatusChange(currentPortStatus, status);
if (!ret.isOk()) if (!ret.isOk()) ALOGE("queryPortStatus_1_1 error %s", ret.description().c_str());
ALOGE("queryPortStatus_1_1 error %s", ret.description().c_str());
} else { } else {
ALOGI("Notifying userspace skipped. Callback is NULL"); ALOGI("Notifying userspace skipped. Callback is NULL");
} }
@ -560,14 +535,14 @@ static void uevent_event(uint32_t /*epevents*/, struct data *payload) {
ALOGI("uevent received %s", cp); ALOGI("uevent received %s", cp);
pthread_mutex_lock(&payload->usb->mLock); pthread_mutex_lock(&payload->usb->mLock);
if (payload->usb->mCallback_1_0 != NULL) { if (payload->usb->mCallback_1_0 != NULL) {
sp<IUsbCallback> callback_V1_1 = IUsbCallback::castFrom(payload->usb->mCallback_1_0); sp<IUsbCallback> callback_V1_1 =
IUsbCallback::castFrom(payload->usb->mCallback_1_0);
Return<void> ret; Return<void> ret;
// V1_1 callback // V1_1 callback
if (callback_V1_1 != NULL) { if (callback_V1_1 != NULL) {
Status status = getPortStatusHelper(&currentPortStatus_1_1, false); Status status = getPortStatusHelper(&currentPortStatus_1_1, false);
ret = callback_V1_1->notifyPortStatusChange_1_1( ret = callback_V1_1->notifyPortStatusChange_1_1(currentPortStatus_1_1, status);
currentPortStatus_1_1, status);
} else { // V1_0 callback } else { // V1_0 callback
Status status = getPortStatusHelper(&currentPortStatus_1_1, true); Status status = getPortStatusHelper(&currentPortStatus_1_1, true);
@ -581,8 +556,8 @@ static void uevent_event(uint32_t /*epevents*/, struct data *payload) {
for (unsigned long i = 0; i < currentPortStatus_1_1.size(); i++) for (unsigned long i = 0; i < currentPortStatus_1_1.size(); i++)
currentPortStatus[i] = currentPortStatus_1_1[i].status; currentPortStatus[i] = currentPortStatus_1_1[i].status;
ret = payload->usb->mCallback_1_0->notifyPortStatusChange( ret = payload->usb->mCallback_1_0->notifyPortStatusChange(currentPortStatus,
currentPortStatus, status); status);
} }
if (!ret.isOk()) ALOGE("error %s", ret.description().c_str()); if (!ret.isOk()) ALOGE("error %s", ret.description().c_str());
} else { } else {
@ -593,9 +568,12 @@ static void uevent_event(uint32_t /*epevents*/, struct data *payload) {
// Role switch is not in progress and port is in disconnected state // Role switch is not in progress and port is in disconnected state
if (!pthread_mutex_trylock(&payload->usb->mRoleSwitchLock)) { if (!pthread_mutex_trylock(&payload->usb->mRoleSwitchLock)) {
for (unsigned long i = 0; i < currentPortStatus_1_1.size(); i++) { for (unsigned long i = 0; i < currentPortStatus_1_1.size(); i++) {
DIR *dp = opendir(std::string("/sys/class/typec/" DIR* dp = opendir(
+ std::string(currentPortStatus_1_1[i].status.portName.c_str()) std::string(
+ "-partner").c_str()); "/sys/class/typec/" +
std::string(currentPortStatus_1_1[i].status.portName.c_str()) +
"-partner")
.c_str());
if (dp == NULL) { if (dp == NULL) {
// PortRole role = {.role = static_cast<uint32_t>(PortMode::UFP)}; // PortRole role = {.role = static_cast<uint32_t>(PortMode::UFP)};
switchToDrp(currentPortStatus_1_1[i].status.portName); switchToDrp(currentPortStatus_1_1[i].status.portName);
@ -607,7 +585,8 @@ static void uevent_event(uint32_t /*epevents*/, struct data *payload) {
} }
break; break;
} else if (std::regex_match(cp, match, } else if (std::regex_match(cp, match,
std::regex("add@(/devices/soc/a800000\\.ssusb/a800000\\.dwc3/xhci-hcd\\.0\\.auto/" std::regex("add@(/devices/soc/a800000\\.ssusb/a800000\\.dwc3/"
"xhci-hcd\\.0\\.auto/"
"usb\\d/\\d-\\d)/.*"))) { "usb\\d/\\d-\\d)/.*"))) {
if (match.size() == 2) { if (match.size() == 2) {
std::csub_match submatch = match[1]; std::csub_match submatch = match[1];
@ -616,7 +595,8 @@ static void uevent_event(uint32_t /*epevents*/, struct data *payload) {
} }
/* advance to after the next \0 */ /* advance to after the next \0 */
while (*cp++) {} while (*cp++) {
}
} }
} }
@ -666,8 +646,8 @@ void *work(void *param) {
for (int n = 0; n < nevents; ++n) { for (int n = 0; n < nevents; ++n) {
if (events[n].data.ptr) if (events[n].data.ptr)
(*(void (*)(int, struct data *payload))events[n].data.ptr)( (*(void (*)(int, struct data* payload))events[n].data.ptr)(events[n].events,
events[n].events, &payload); &payload);
} }
} }
@ -690,12 +670,10 @@ void sighandler(int sig) {
} }
Return<void> Usb::setCallback(const sp<V1_0::IUsbCallback>& callback) { Return<void> Usb::setCallback(const sp<V1_0::IUsbCallback>& callback) {
sp<IUsbCallback> callback_V1_1 = IUsbCallback::castFrom(callback); sp<IUsbCallback> callback_V1_1 = IUsbCallback::castFrom(callback);
if (callback != NULL) if (callback != NULL)
if (callback_V1_1 == NULL) if (callback_V1_1 == NULL) ALOGI("Registering 1.0 callback");
ALOGI("Registering 1.0 callback");
pthread_mutex_lock(&mLock); pthread_mutex_lock(&mLock);
/* /*
@ -784,7 +762,7 @@ void checkUsbDeviceAutoSuspend(const std::string& devicePath) {
} }
} // namespace implementation } // namespace implementation
} // namespace V1_0 } // namespace V1_1
} // namespace usb } // namespace usb
} // namespace hardware } // namespace hardware
} // namespace android } // namespace android

View file

@ -2,8 +2,8 @@
#define ANDROID_HARDWARE_USB_V1_1_USB_H #define ANDROID_HARDWARE_USB_V1_1_USB_H
#include <android/hardware/usb/1.1/IUsb.h> #include <android/hardware/usb/1.1/IUsb.h>
#include <android/hardware/usb/1.1/types.h>
#include <android/hardware/usb/1.1/IUsbCallback.h> #include <android/hardware/usb/1.1/IUsbCallback.h>
#include <android/hardware/usb/1.1/types.h>
#include <hidl/Status.h> #include <hidl/Status.h>
#include <utils/Log.h> #include <utils/Log.h>
@ -20,10 +20,17 @@ namespace usb {
namespace V1_1 { namespace V1_1 {
namespace implementation { namespace implementation {
using ::android::hardware::usb::V1_0::PortRole; using ::android::sp;
using ::android::hardware::usb::V1_0::PortRoleType; 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::PortDataRole;
using ::android::hardware::usb::V1_0::PortPowerRole; 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_0::Status;
using ::android::hardware::usb::V1_1::IUsb; using ::android::hardware::usb::V1_1::IUsb;
using ::android::hardware::usb::V1_1::IUsbCallback; 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::hardware::usb::V1_1::PortStatus_1_1;
using ::android::hidl::base::V1_0::DebugInfo; using ::android::hidl::base::V1_0::DebugInfo;
using ::android::hidl::base::V1_0::IBase; 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 { struct Usb : public IUsb {
Usb(); Usb();
@ -46,7 +46,6 @@ struct Usb : public IUsb {
Return<void> setCallback(const sp<V1_0::IUsbCallback>& callback) override; Return<void> setCallback(const sp<V1_0::IUsbCallback>& callback) override;
Return<void> queryPortStatus() override; Return<void> queryPortStatus() override;
sp<V1_0::IUsbCallback> mCallback_1_0; sp<V1_0::IUsbCallback> mCallback_1_0;
// Protects mCallback variable // Protects mCallback variable
pthread_mutex_t mLock; pthread_mutex_t mLock;
@ -64,7 +63,7 @@ struct Usb : public IUsb {
}; };
} // namespace implementation } // namespace implementation
} // namespace V1_0 } // namespace V1_1
} // namespace usb } // namespace usb
} // namespace hardware } // namespace hardware
} // namespace android } // namespace android

View file

@ -29,8 +29,8 @@ using android::hardware::joinRpcThreadpool;
using android::hardware::usb::V1_1::IUsb; using android::hardware::usb::V1_1::IUsb;
using android::hardware::usb::V1_1::implementation::Usb; using android::hardware::usb::V1_1::implementation::Usb;
using android::status_t;
using android::OK; using android::OK;
using android::status_t;
int main() { int main() {
android::sp<IUsb> service = new Usb(); android::sp<IUsb> service = new Usb();
@ -48,5 +48,4 @@ int main() {
// Under noraml cases, execution will not reach this line. // Under noraml cases, execution will not reach this line.
ALOGI("USB HAL failed to join thread pool."); ALOGI("USB HAL failed to join thread pool.");
return 1; return 1;
} }