mirror of
https://github.com/chararomandroid/android_device_samsung_a20
synced 2026-08-23 12:35:33 -04:00
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:
parent
6bc1c25485
commit
098179eabb
47 changed files with 1545 additions and 1709 deletions
|
|
@ -24,9 +24,9 @@
|
|||
#include "BiometricsFingerprint.h"
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <fstream>
|
||||
#include <inttypes.h>
|
||||
#include <unistd.h>
|
||||
#include <fstream>
|
||||
|
||||
#ifdef HAS_FINGERPRINT_GESTURES
|
||||
#include <fcntl.h>
|
||||
|
|
@ -58,9 +58,8 @@ BiometricsFingerprint::BiometricsFingerprint() : mClientCallback(nullptr) {
|
|||
return;
|
||||
}
|
||||
|
||||
int err = ioctl(uinputFd, UI_SET_EVBIT, EV_KEY) |
|
||||
ioctl(uinputFd, UI_SET_KEYBIT, KEY_UP) |
|
||||
ioctl(uinputFd, UI_SET_KEYBIT, KEY_DOWN);
|
||||
int err = ioctl(uinputFd, UI_SET_EVBIT, EV_KEY) | ioctl(uinputFd, UI_SET_KEYBIT, KEY_UP) |
|
||||
ioctl(uinputFd, UI_SET_KEYBIT, KEY_DOWN);
|
||||
if (err != 0) {
|
||||
LOG(ERROR) << "Unable to enable key events";
|
||||
return;
|
||||
|
|
@ -71,14 +70,14 @@ BiometricsFingerprint::BiometricsFingerprint() : mClientCallback(nullptr) {
|
|||
|
||||
err = write(uinputFd, &uidev, sizeof(uidev));
|
||||
if (err < 0) {
|
||||
LOG(ERROR) << "Write user device to uinput node failed";
|
||||
return;
|
||||
LOG(ERROR) << "Write user device to uinput node failed";
|
||||
return;
|
||||
}
|
||||
|
||||
err = ioctl(uinputFd, UI_DEV_CREATE);
|
||||
if (err < 0) {
|
||||
LOG(ERROR) << "Unable to create uinput device";
|
||||
return;
|
||||
LOG(ERROR) << "Unable to create uinput device";
|
||||
return;
|
||||
}
|
||||
|
||||
LOG(INFO) << "Successfully registered uinput-sec-fp for fingerprint gestures";
|
||||
|
|
@ -200,7 +199,7 @@ FingerprintAcquiredInfo BiometricsFingerprint::VendorAcquiredFilter(int32_t info
|
|||
}
|
||||
|
||||
Return<uint64_t> BiometricsFingerprint::setNotify(
|
||||
const sp<IBiometricsFingerprintClientCallback>& clientCallback) {
|
||||
const sp<IBiometricsFingerprintClientCallback>& clientCallback) {
|
||||
std::lock_guard<std::mutex> lock(mClientCallbackMutex);
|
||||
mClientCallback = clientCallback;
|
||||
// This is here because HAL 2.3 doesn't have a way to propagate a
|
||||
|
|
@ -286,33 +285,33 @@ bool BiometricsFingerprint::openHal() {
|
|||
if (handle) {
|
||||
int err;
|
||||
|
||||
ss_fingerprint_close =
|
||||
reinterpret_cast<typeof(ss_fingerprint_close)>(dlsym(handle, "ss_fingerprint_close"));
|
||||
ss_fingerprint_close = reinterpret_cast<typeof(ss_fingerprint_close)>(
|
||||
dlsym(handle, "ss_fingerprint_close"));
|
||||
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"));
|
||||
|
||||
ss_set_notify_callback = reinterpret_cast<typeof(ss_set_notify_callback)>(
|
||||
dlsym(handle, "ss_set_notify_callback"));
|
||||
dlsym(handle, "ss_set_notify_callback"));
|
||||
ss_fingerprint_pre_enroll = reinterpret_cast<typeof(ss_fingerprint_pre_enroll)>(
|
||||
dlsym(handle, "ss_fingerprint_pre_enroll"));
|
||||
ss_fingerprint_enroll =
|
||||
reinterpret_cast<typeof(ss_fingerprint_enroll)>(dlsym(handle, "ss_fingerprint_enroll"));
|
||||
dlsym(handle, "ss_fingerprint_pre_enroll"));
|
||||
ss_fingerprint_enroll = reinterpret_cast<typeof(ss_fingerprint_enroll)>(
|
||||
dlsym(handle, "ss_fingerprint_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)>(
|
||||
dlsym(handle, "ss_fingerprint_get_auth_id"));
|
||||
ss_fingerprint_cancel =
|
||||
reinterpret_cast<typeof(ss_fingerprint_cancel)>(dlsym(handle, "ss_fingerprint_cancel"));
|
||||
dlsym(handle, "ss_fingerprint_get_auth_id"));
|
||||
ss_fingerprint_cancel = reinterpret_cast<typeof(ss_fingerprint_cancel)>(
|
||||
dlsym(handle, "ss_fingerprint_cancel"));
|
||||
ss_fingerprint_enumerate = reinterpret_cast<typeof(ss_fingerprint_enumerate)>(
|
||||
dlsym(handle, "ss_fingerprint_enumerate"));
|
||||
ss_fingerprint_remove =
|
||||
reinterpret_cast<typeof(ss_fingerprint_remove)>(dlsym(handle, "ss_fingerprint_remove"));
|
||||
dlsym(handle, "ss_fingerprint_enumerate"));
|
||||
ss_fingerprint_remove = reinterpret_cast<typeof(ss_fingerprint_remove)>(
|
||||
dlsym(handle, "ss_fingerprint_remove"));
|
||||
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)>(
|
||||
dlsym(handle, "ss_fingerprint_authenticate"));
|
||||
dlsym(handle, "ss_fingerprint_authenticate"));
|
||||
ss_fingerprint_request = reinterpret_cast<typeof(ss_fingerprint_request)>(
|
||||
dlsym(handle, "ss_fingerprint_request"));
|
||||
dlsym(handle, "ss_fingerprint_request"));
|
||||
|
||||
if ((err = ss_fingerprint_open(nullptr)) != 0) {
|
||||
LOG(ERROR) << "Can't open fingerprint, error: " << err;
|
||||
|
|
@ -332,7 +331,7 @@ bool BiometricsFingerprint::openHal() {
|
|||
|
||||
void BiometricsFingerprint::notify(const fingerprint_msg_t* msg) {
|
||||
BiometricsFingerprint* thisPtr =
|
||||
static_cast<BiometricsFingerprint*>(BiometricsFingerprint::getInstance());
|
||||
static_cast<BiometricsFingerprint*>(BiometricsFingerprint::getInstance());
|
||||
std::lock_guard<std::mutex> lock(thisPtr->mClientCallbackMutex);
|
||||
if (thisPtr == nullptr || thisPtr->mClientCallback == nullptr) {
|
||||
LOG(ERROR) << "Receiving callbacks before the client callback is registered.";
|
||||
|
|
@ -355,7 +354,7 @@ void BiometricsFingerprint::notify(const fingerprint_msg_t* msg) {
|
|||
}
|
||||
int32_t vendorCode = 0;
|
||||
FingerprintAcquiredInfo result =
|
||||
VendorAcquiredFilter(msg->data.acquired.acquired_info, &vendorCode);
|
||||
VendorAcquiredFilter(msg->data.acquired.acquired_info, &vendorCode);
|
||||
LOG(DEBUG) << "onAcquired(" << static_cast<int>(result) << ")";
|
||||
if (!thisPtr->mClientCallback->onAcquired(devId, result, vendorCode).isOk()) {
|
||||
LOG(ERROR) << "failed to invoke fingerprint onAcquired callback";
|
||||
|
|
@ -364,10 +363,10 @@ void BiometricsFingerprint::notify(const fingerprint_msg_t* msg) {
|
|||
case FINGERPRINT_TEMPLATE_ENROLLING:
|
||||
#ifdef USES_PERCENTAGE_SAMPLES
|
||||
const_cast<fingerprint_msg_t*>(msg)->data.enroll.samples_remaining =
|
||||
100 - msg->data.enroll.samples_remaining;
|
||||
100 - msg->data.enroll.samples_remaining;
|
||||
#endif
|
||||
#ifdef CALL_CANCEL_ON_ENROLL_COMPLETION
|
||||
if(msg->data.enroll.samples_remaining == 0) {
|
||||
if (msg->data.enroll.samples_remaining == 0) {
|
||||
thisPtr->ss_fingerprint_cancel();
|
||||
}
|
||||
#endif
|
||||
|
|
@ -375,9 +374,10 @@ void BiometricsFingerprint::notify(const fingerprint_msg_t* msg) {
|
|||
<< ", gid=" << msg->data.enroll.finger.gid
|
||||
<< ", rem=" << msg->data.enroll.samples_remaining << ")";
|
||||
if (!thisPtr->mClientCallback
|
||||
->onEnrollResult(devId, msg->data.enroll.finger.fid,
|
||||
msg->data.enroll.finger.gid, msg->data.enroll.samples_remaining)
|
||||
.isOk()) {
|
||||
->onEnrollResult(devId, msg->data.enroll.finger.fid,
|
||||
msg->data.enroll.finger.gid,
|
||||
msg->data.enroll.samples_remaining)
|
||||
.isOk()) {
|
||||
LOG(ERROR) << "failed to invoke fingerprint onEnrollResult callback";
|
||||
}
|
||||
break;
|
||||
|
|
@ -386,9 +386,10 @@ void BiometricsFingerprint::notify(const fingerprint_msg_t* msg) {
|
|||
<< ", gid=" << msg->data.removed.finger.gid
|
||||
<< ", rem=" << msg->data.removed.remaining_templates << ")";
|
||||
if (!thisPtr->mClientCallback
|
||||
->onRemoved(devId, msg->data.removed.finger.fid, msg->data.removed.finger.gid,
|
||||
msg->data.removed.remaining_templates)
|
||||
.isOk()) {
|
||||
->onRemoved(devId, msg->data.removed.finger.fid,
|
||||
msg->data.removed.finger.gid,
|
||||
msg->data.removed.remaining_templates)
|
||||
.isOk()) {
|
||||
LOG(ERROR) << "failed to invoke fingerprint onRemoved callback";
|
||||
}
|
||||
break;
|
||||
|
|
@ -398,19 +399,20 @@ void BiometricsFingerprint::notify(const fingerprint_msg_t* msg) {
|
|||
if (msg->data.authenticated.finger.fid != 0) {
|
||||
const uint8_t* hat = reinterpret_cast<const uint8_t*>(&msg->data.authenticated.hat);
|
||||
const hidl_vec<uint8_t> token(
|
||||
std::vector<uint8_t>(hat, hat + sizeof(msg->data.authenticated.hat)));
|
||||
std::vector<uint8_t>(hat, hat + sizeof(msg->data.authenticated.hat)));
|
||||
if (!thisPtr->mClientCallback
|
||||
->onAuthenticated(devId, msg->data.authenticated.finger.fid,
|
||||
msg->data.authenticated.finger.gid, token)
|
||||
.isOk()) {
|
||||
->onAuthenticated(devId, msg->data.authenticated.finger.fid,
|
||||
msg->data.authenticated.finger.gid, token)
|
||||
.isOk()) {
|
||||
LOG(ERROR) << "failed to invoke fingerprint onAuthenticated callback";
|
||||
}
|
||||
} else {
|
||||
// Not a recognized fingerprint
|
||||
if (!thisPtr->mClientCallback
|
||||
->onAuthenticated(devId, msg->data.authenticated.finger.fid,
|
||||
msg->data.authenticated.finger.gid, hidl_vec<uint8_t>())
|
||||
.isOk()) {
|
||||
->onAuthenticated(devId, msg->data.authenticated.finger.fid,
|
||||
msg->data.authenticated.finger.gid,
|
||||
hidl_vec<uint8_t>())
|
||||
.isOk()) {
|
||||
LOG(ERROR) << "failed to invoke fingerprint onAuthenticated callback";
|
||||
}
|
||||
}
|
||||
|
|
@ -420,10 +422,10 @@ void BiometricsFingerprint::notify(const fingerprint_msg_t* msg) {
|
|||
<< ", gid=" << msg->data.enumerated.finger.gid
|
||||
<< ", rem=" << msg->data.enumerated.remaining_templates << ")";
|
||||
if (!thisPtr->mClientCallback
|
||||
->onEnumerate(devId, msg->data.enumerated.finger.fid,
|
||||
msg->data.enumerated.finger.gid,
|
||||
msg->data.enumerated.remaining_templates)
|
||||
.isOk()) {
|
||||
->onEnumerate(devId, msg->data.enumerated.finger.fid,
|
||||
msg->data.enumerated.finger.gid,
|
||||
msg->data.enumerated.remaining_templates)
|
||||
.isOk()) {
|
||||
LOG(ERROR) << "failed to invoke fingerprint onEnumerate callback";
|
||||
}
|
||||
break;
|
||||
|
|
@ -436,8 +438,7 @@ void BiometricsFingerprint::handleEvent(int eventCode) {
|
|||
case SEM_FINGERPRINT_EVENT_GESTURE_SWIPE_DOWN:
|
||||
case SEM_FINGERPRINT_EVENT_GESTURE_SWIPE_UP:
|
||||
struct input_event event {};
|
||||
int keycode = eventCode == SEM_FINGERPRINT_EVENT_GESTURE_SWIPE_UP ?
|
||||
KEY_UP : KEY_DOWN;
|
||||
int keycode = eventCode == SEM_FINGERPRINT_EVENT_GESTURE_SWIPE_UP ? KEY_UP : KEY_DOWN;
|
||||
int err;
|
||||
|
||||
// Report the key
|
||||
|
|
@ -479,7 +480,7 @@ void BiometricsFingerprint::handleEvent(int eventCode) {
|
|||
LOG(ERROR) << "Write EV_SYN to uinput node failed";
|
||||
return;
|
||||
}
|
||||
break;
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
@ -496,8 +497,8 @@ int BiometricsFingerprint::waitForSensor(std::chrono::milliseconds pollWait,
|
|||
int sensorStatus = SEM_SENSOR_STATUS_WORKING;
|
||||
std::chrono::milliseconds timeWaited = 0ms;
|
||||
while (sensorStatus != SEM_SENSOR_STATUS_OK) {
|
||||
if (sensorStatus == SEM_SENSOR_STATUS_CALIBRATION_ERROR
|
||||
|| sensorStatus == SEM_SENSOR_STATUS_ERROR){
|
||||
if (sensorStatus == SEM_SENSOR_STATUS_CALIBRATION_ERROR ||
|
||||
sensorStatus == SEM_SENSOR_STATUS_ERROR) {
|
||||
return -1;
|
||||
}
|
||||
if (timeWaited >= timeOut) {
|
||||
|
|
|
|||
|
|
@ -24,12 +24,12 @@
|
|||
#include <linux/uinput.h>
|
||||
#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/hardware.h>
|
||||
#include <hidl/MQDescriptor.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"
|
||||
|
||||
|
|
@ -47,11 +47,11 @@ using ::android::hardware::hidl_string;
|
|||
using ::android::hardware::hidl_vec;
|
||||
using ::android::hardware::Return;
|
||||
using ::android::hardware::Void;
|
||||
using ::android::hardware::biometrics::fingerprint::V2_3::IBiometricsFingerprint;
|
||||
using ::android::hardware::biometrics::fingerprint::V2_1::IBiometricsFingerprintClientCallback;
|
||||
using ::android::hardware::biometrics::fingerprint::V2_1::FingerprintAcquiredInfo;
|
||||
using ::android::hardware::biometrics::fingerprint::V2_1::FingerprintError;
|
||||
using ::android::hardware::biometrics::fingerprint::V2_1::IBiometricsFingerprintClientCallback;
|
||||
using ::android::hardware::biometrics::fingerprint::V2_1::RequestStatus;
|
||||
using ::android::hardware::biometrics::fingerprint::V2_3::IBiometricsFingerprint;
|
||||
|
||||
struct BiometricsFingerprint : public IBiometricsFingerprint {
|
||||
BiometricsFingerprint();
|
||||
|
|
@ -60,9 +60,10 @@ struct BiometricsFingerprint : public IBiometricsFingerprint {
|
|||
// Method to wrap legacy HAL with BiometricsFingerprint class
|
||||
static IBiometricsFingerprint* getInstance();
|
||||
|
||||
// Methods from ::android::hardware::biometrics::fingerprint::V2_3::IBiometricsFingerprint follow.
|
||||
// Methods from ::android::hardware::biometrics::fingerprint::V2_3::IBiometricsFingerprint
|
||||
// follow.
|
||||
Return<uint64_t> setNotify(
|
||||
const sp<IBiometricsFingerprintClientCallback>& clientCallback) override;
|
||||
const sp<IBiometricsFingerprintClientCallback>& clientCallback) override;
|
||||
Return<uint64_t> preEnroll() override;
|
||||
Return<RequestStatus> enroll(const hidl_array<uint8_t, 69>& hat, uint32_t gid,
|
||||
uint32_t timeoutSec) override;
|
||||
|
|
@ -76,15 +77,15 @@ struct BiometricsFingerprint : public IBiometricsFingerprint {
|
|||
Return<bool> isUdfps(uint32_t sensorID) override;
|
||||
Return<void> onFingerDown(uint32_t x, uint32_t y, float minor, float major) override;
|
||||
Return<void> onFingerUp() override;
|
||||
Return<void> onShowUdfpsOverlay(){ return Void();}
|
||||
Return<void> onHideUdfpsOverlay(){ return Void();}
|
||||
Return<void> onShowUdfpsOverlay() { return Void(); }
|
||||
Return<void> onHideUdfpsOverlay() { return Void(); }
|
||||
|
||||
private:
|
||||
bool openHal();
|
||||
int request(int cmd, int param);
|
||||
int waitForSensor(std::chrono::milliseconds pollWait, std::chrono::milliseconds timeOut);
|
||||
static void notify(
|
||||
const fingerprint_msg_t* msg); /* Static callback for legacy HAL implementation */
|
||||
const fingerprint_msg_t* msg); /* Static callback for legacy HAL implementation */
|
||||
void handleEvent(int eventCode);
|
||||
static Return<RequestStatus> ErrorFilter(int32_t error);
|
||||
static FingerprintError VendorErrorFilter(int32_t error, int32_t* vendorCode);
|
||||
|
|
@ -111,7 +112,8 @@ struct BiometricsFingerprint : public IBiometricsFingerprint {
|
|||
int (*ss_fingerprint_remove)(uint32_t gid, uint32_t fid);
|
||||
int (*ss_fingerprint_set_active_group)(uint32_t gid, const char* store_path);
|
||||
int (*ss_fingerprint_authenticate)(uint64_t operation_id, uint32_t gid);
|
||||
int (*ss_fingerprint_request)(uint32_t cmd, char *inBuf, uint32_t inBuf_length, char *outBuf, uint32_t outBuf_length, uint32_t param);
|
||||
int (*ss_fingerprint_request)(uint32_t cmd, char* inBuf, uint32_t inBuf_length, char* outBuf,
|
||||
uint32_t outBuf_length, uint32_t param);
|
||||
};
|
||||
|
||||
} // namespace implementation
|
||||
|
|
|
|||
|
|
@ -101,4 +101,4 @@
|
|||
#define SEM_SENSOR_STATUS_OK 100040
|
||||
#define SEM_SENSOR_STATUS_WORKING 100041
|
||||
|
||||
#endif // SAMSUNG_FINGERPRINT_CONSTANTS_H
|
||||
#endif // SAMSUNG_FINGERPRINT_CONSTANTS_H
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ IKeymasterDevice* CreateSKeymasterDevice(SecurityLevel securityLevel);
|
|||
|
||||
int main() {
|
||||
IKeymasterDevice* keymaster =
|
||||
skeymaster::CreateSKeymasterDevice(SecurityLevel::TRUSTED_ENVIRONMENT);
|
||||
skeymaster::CreateSKeymasterDevice(SecurityLevel::TRUSTED_ENVIRONMENT);
|
||||
|
||||
configureRpcThreadpool(1, true);
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ namespace implementation {
|
|||
static bool UseMultiHal() {
|
||||
const std::string& name = MULTI_HAL_CONFIG_FILE_PATH;
|
||||
struct stat buffer;
|
||||
return (stat (name.c_str(), &buffer) == 0);
|
||||
return (stat(name.c_str(), &buffer) == 0);
|
||||
}
|
||||
|
||||
static Result ResultFromStatus(status_t err) {
|
||||
|
|
@ -55,28 +55,20 @@ static Result ResultFromStatus(status_t err) {
|
|||
}
|
||||
}
|
||||
|
||||
Sensors::Sensors()
|
||||
: mInitCheck(NO_INIT),
|
||||
mSensorModule(nullptr),
|
||||
mSensorDevice(nullptr) {
|
||||
Sensors::Sensors() : mInitCheck(NO_INIT), mSensorModule(nullptr), mSensorDevice(nullptr) {
|
||||
status_t err = OK;
|
||||
if (UseMultiHal()) {
|
||||
mSensorModule = ::get_multi_hal_module_info();
|
||||
} else {
|
||||
err = hw_get_module(
|
||||
SENSORS_HARDWARE_MODULE_ID,
|
||||
(hw_module_t const **)&mSensorModule);
|
||||
err = hw_get_module(SENSORS_HARDWARE_MODULE_ID, (hw_module_t const**)&mSensorModule);
|
||||
}
|
||||
if (mSensorModule == NULL) {
|
||||
err = UNKNOWN_ERROR;
|
||||
}
|
||||
|
||||
if (err != OK) {
|
||||
LOG(ERROR) << "Couldn't load "
|
||||
<< SENSORS_HARDWARE_MODULE_ID
|
||||
<< " module ("
|
||||
<< strerror(-err)
|
||||
<< ")";
|
||||
LOG(ERROR) << "Couldn't load " << SENSORS_HARDWARE_MODULE_ID << " module ("
|
||||
<< strerror(-err) << ")";
|
||||
|
||||
mInitCheck = err;
|
||||
return;
|
||||
|
|
@ -85,11 +77,8 @@ Sensors::Sensors()
|
|||
err = sensors_open_1(&mSensorModule->common, &mSensorDevice);
|
||||
|
||||
if (err != OK) {
|
||||
LOG(ERROR) << "Couldn't open device for module "
|
||||
<< SENSORS_HARDWARE_MODULE_ID
|
||||
<< " ("
|
||||
<< strerror(-err)
|
||||
<< ")";
|
||||
LOG(ERROR) << "Couldn't open device for module " << SENSORS_HARDWARE_MODULE_ID << " ("
|
||||
<< strerror(-err) << ")";
|
||||
|
||||
mInitCheck = err;
|
||||
return;
|
||||
|
|
@ -119,15 +108,15 @@ status_t Sensors::initCheck() const {
|
|||
}
|
||||
|
||||
Return<void> Sensors::getSensorsList(getSensorsList_cb _hidl_cb) {
|
||||
sensor_t const *list;
|
||||
sensor_t const* list;
|
||||
size_t count = mSensorModule->get_sensors_list(mSensorModule, &list);
|
||||
|
||||
hidl_vec<SensorInfo> out;
|
||||
out.resize(count);
|
||||
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
const sensor_t *src = &list[i];
|
||||
SensorInfo *dst = &out[i];
|
||||
const sensor_t* src = &list[i];
|
||||
SensorInfo* dst = &out[i];
|
||||
|
||||
convertFromSensor(*src, dst);
|
||||
|
||||
|
|
@ -166,31 +155,26 @@ int Sensors::getHalDeviceVersion() const {
|
|||
}
|
||||
|
||||
Return<Result> Sensors::setOperationMode(OperationMode mode) {
|
||||
if (getHalDeviceVersion() < SENSORS_DEVICE_API_VERSION_1_4
|
||||
|| mSensorModule->set_operation_mode == nullptr) {
|
||||
if (getHalDeviceVersion() < SENSORS_DEVICE_API_VERSION_1_4 ||
|
||||
mSensorModule->set_operation_mode == nullptr) {
|
||||
return Result::INVALID_OPERATION;
|
||||
}
|
||||
return ResultFromStatus(mSensorModule->set_operation_mode((uint32_t)mode));
|
||||
}
|
||||
|
||||
Return<Result> Sensors::activate(
|
||||
int32_t sensor_handle, bool enabled) {
|
||||
return ResultFromStatus(
|
||||
mSensorDevice->activate(
|
||||
reinterpret_cast<sensors_poll_device_t *>(mSensorDevice),
|
||||
sensor_handle,
|
||||
enabled));
|
||||
Return<Result> Sensors::activate(int32_t sensor_handle, bool enabled) {
|
||||
return ResultFromStatus(mSensorDevice->activate(
|
||||
reinterpret_cast<sensors_poll_device_t*>(mSensorDevice), sensor_handle, enabled));
|
||||
}
|
||||
|
||||
Return<void> Sensors::poll(int32_t maxCount, poll_cb _hidl_cb) {
|
||||
|
||||
hidl_vec<Event> out;
|
||||
hidl_vec<SensorInfo> dynamicSensorsAdded;
|
||||
|
||||
std::unique_ptr<sensors_event_t[]> data;
|
||||
int err = android::NO_ERROR;
|
||||
|
||||
{ // scope of reentry lock
|
||||
{ // scope of reentry lock
|
||||
|
||||
// This enforces a single client, meaning that a maximum of one client can call poll().
|
||||
// If this function is re-entred, it means that we are stuck in a state that may prevent
|
||||
|
|
@ -200,11 +184,11 @@ Return<void> Sensors::poll(int32_t maxCount, poll_cb _hidl_cb) {
|
|||
//
|
||||
// This function must not call _hidl_cb(...) or return until there is no risk of blocking.
|
||||
std::unique_lock<std::mutex> lock(mPollLock, std::try_to_lock);
|
||||
if(!lock.owns_lock()){
|
||||
if (!lock.owns_lock()) {
|
||||
// cannot get the lock, hidl service will go into deadlock if it is not restarted.
|
||||
// This is guaranteed to not trigger in passthrough mode.
|
||||
LOG(ERROR) <<
|
||||
"ISensors::poll() re-entry. I do not know what to do except killing myself.";
|
||||
LOG(ERROR)
|
||||
<< "ISensors::poll() re-entry. I do not know what to do except killing myself.";
|
||||
::exit(-1);
|
||||
}
|
||||
|
||||
|
|
@ -213,9 +197,8 @@ Return<void> Sensors::poll(int32_t maxCount, poll_cb _hidl_cb) {
|
|||
} else {
|
||||
int bufferSize = maxCount <= kPollMaxBufferSize ? maxCount : kPollMaxBufferSize;
|
||||
data.reset(new sensors_event_t[bufferSize]);
|
||||
err = mSensorDevice->poll(
|
||||
reinterpret_cast<sensors_poll_device_t *>(mSensorDevice),
|
||||
data.get(), bufferSize);
|
||||
err = mSensorDevice->poll(reinterpret_cast<sensors_poll_device_t*>(mSensorDevice),
|
||||
data.get(), bufferSize);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -231,7 +214,7 @@ Return<void> Sensors::poll(int32_t maxCount, poll_cb _hidl_cb) {
|
|||
continue;
|
||||
}
|
||||
|
||||
const dynamic_sensor_meta_event_t *dyn = &data[i].dynamic_sensor_meta;
|
||||
const dynamic_sensor_meta_event_t* dyn = &data[i].dynamic_sensor_meta;
|
||||
|
||||
if (!dyn->connected) {
|
||||
continue;
|
||||
|
|
@ -256,17 +239,10 @@ Return<void> Sensors::poll(int32_t maxCount, poll_cb _hidl_cb) {
|
|||
return Void();
|
||||
}
|
||||
|
||||
Return<Result> Sensors::batch(
|
||||
int32_t sensor_handle,
|
||||
int64_t sampling_period_ns,
|
||||
int64_t max_report_latency_ns) {
|
||||
return ResultFromStatus(
|
||||
mSensorDevice->batch(
|
||||
mSensorDevice,
|
||||
sensor_handle,
|
||||
0, /*flags*/
|
||||
sampling_period_ns,
|
||||
max_report_latency_ns));
|
||||
Return<Result> Sensors::batch(int32_t sensor_handle, int64_t sampling_period_ns,
|
||||
int64_t max_report_latency_ns) {
|
||||
return ResultFromStatus(mSensorDevice->batch(mSensorDevice, sensor_handle, 0, /*flags*/
|
||||
sampling_period_ns, max_report_latency_ns));
|
||||
}
|
||||
|
||||
Return<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) {
|
||||
if (getHalDeviceVersion() < SENSORS_DEVICE_API_VERSION_1_4
|
||||
|| mSensorDevice->inject_sensor_data == nullptr) {
|
||||
if (getHalDeviceVersion() < SENSORS_DEVICE_API_VERSION_1_4 ||
|
||||
mSensorDevice->inject_sensor_data == nullptr) {
|
||||
return Result::INVALID_OPERATION;
|
||||
}
|
||||
|
||||
sensors_event_t out;
|
||||
convertToSensorEvent(event, &out);
|
||||
|
||||
return ResultFromStatus(
|
||||
mSensorDevice->inject_sensor_data(mSensorDevice, &out));
|
||||
return ResultFromStatus(mSensorDevice->inject_sensor_data(mSensorDevice, &out));
|
||||
}
|
||||
|
||||
Return<void> Sensors::registerDirectChannel(
|
||||
const SharedMemInfo& mem, registerDirectChannel_cb _hidl_cb) {
|
||||
if (mSensorDevice->register_direct_channel == nullptr
|
||||
|| mSensorDevice->config_direct_report == nullptr) {
|
||||
Return<void> Sensors::registerDirectChannel(const SharedMemInfo& mem,
|
||||
registerDirectChannel_cb _hidl_cb) {
|
||||
if (mSensorDevice->register_direct_channel == nullptr ||
|
||||
mSensorDevice->config_direct_report == nullptr) {
|
||||
// HAL does not support
|
||||
_hidl_cb(Result::INVALID_OPERATION, -1);
|
||||
return Void();
|
||||
|
|
@ -297,8 +272,8 @@ Return<void> Sensors::registerDirectChannel(
|
|||
|
||||
sensors_direct_mem_t m;
|
||||
if (!convertFromSharedMemInfo(mem, &m)) {
|
||||
_hidl_cb(Result::BAD_VALUE, -1);
|
||||
return Void();
|
||||
_hidl_cb(Result::BAD_VALUE, -1);
|
||||
return Void();
|
||||
}
|
||||
|
||||
int err = mSensorDevice->register_direct_channel(mSensorDevice, &m, -1);
|
||||
|
|
@ -313,8 +288,8 @@ Return<void> Sensors::registerDirectChannel(
|
|||
}
|
||||
|
||||
Return<Result> Sensors::unregisterDirectChannel(int32_t channelHandle) {
|
||||
if (mSensorDevice->register_direct_channel == nullptr
|
||||
|| mSensorDevice->config_direct_report == nullptr) {
|
||||
if (mSensorDevice->register_direct_channel == nullptr ||
|
||||
mSensorDevice->config_direct_report == nullptr) {
|
||||
// HAL does not support
|
||||
return Result::INVALID_OPERATION;
|
||||
}
|
||||
|
|
@ -324,26 +299,22 @@ Return<Result> Sensors::unregisterDirectChannel(int32_t channelHandle) {
|
|||
return Result::OK;
|
||||
}
|
||||
|
||||
Return<void> Sensors::configDirectReport(
|
||||
int32_t sensorHandle, int32_t channelHandle, RateLevel rate,
|
||||
configDirectReport_cb _hidl_cb) {
|
||||
if (mSensorDevice->register_direct_channel == nullptr
|
||||
|| mSensorDevice->config_direct_report == nullptr) {
|
||||
Return<void> Sensors::configDirectReport(int32_t sensorHandle, int32_t channelHandle,
|
||||
RateLevel rate, configDirectReport_cb _hidl_cb) {
|
||||
if (mSensorDevice->register_direct_channel == nullptr ||
|
||||
mSensorDevice->config_direct_report == nullptr) {
|
||||
// HAL does not support
|
||||
_hidl_cb(Result::INVALID_OPERATION, -1);
|
||||
return Void();
|
||||
}
|
||||
|
||||
sensors_direct_cfg_t cfg = {
|
||||
.rate_level = convertFromRateLevel(rate)
|
||||
};
|
||||
sensors_direct_cfg_t cfg = {.rate_level = convertFromRateLevel(rate)};
|
||||
if (cfg.rate_level < 0) {
|
||||
_hidl_cb(Result::BAD_VALUE, -1);
|
||||
return Void();
|
||||
}
|
||||
|
||||
int err = mSensorDevice->config_direct_report(mSensorDevice,
|
||||
sensorHandle, channelHandle, &cfg);
|
||||
int err = mSensorDevice->config_direct_report(mSensorDevice, sensorHandle, channelHandle, &cfg);
|
||||
|
||||
if (rate == RateLevel::STOP) {
|
||||
_hidl_cb(ResultFromStatus(err), -1);
|
||||
|
|
@ -354,20 +325,18 @@ Return<void> Sensors::configDirectReport(
|
|||
}
|
||||
|
||||
// static
|
||||
void Sensors::convertFromSensorEvents(
|
||||
size_t count,
|
||||
const sensors_event_t *srcArray,
|
||||
hidl_vec<Event> *dstVec) {
|
||||
void Sensors::convertFromSensorEvents(size_t count, const sensors_event_t* srcArray,
|
||||
hidl_vec<Event>* dstVec) {
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
const sensors_event_t &src = srcArray[i];
|
||||
Event *dst = &(*dstVec)[i];
|
||||
const sensors_event_t& src = srcArray[i];
|
||||
Event* dst = &(*dstVec)[i];
|
||||
|
||||
convertFromSensorEvent(src, dst);
|
||||
}
|
||||
}
|
||||
|
||||
ISensors *HIDL_FETCH_ISensors(const char * /* hal */) {
|
||||
Sensors *sensors = new Sensors;
|
||||
ISensors* HIDL_FETCH_ISensors(const char* /* hal */) {
|
||||
Sensors* sensors = new Sensors;
|
||||
if (sensors->initCheck() != OK) {
|
||||
delete sensors;
|
||||
sensors = nullptr;
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ namespace sensors {
|
|||
namespace V1_0 {
|
||||
namespace implementation {
|
||||
|
||||
|
||||
struct Sensors : public ::android::hardware::sensors::V1_0::ISensors {
|
||||
Sensors();
|
||||
|
||||
|
|
@ -39,45 +38,41 @@ struct Sensors : public ::android::hardware::sensors::V1_0::ISensors {
|
|||
|
||||
Return<Result> setOperationMode(OperationMode mode) override;
|
||||
|
||||
Return<Result> activate(
|
||||
int32_t sensor_handle, bool enabled) override;
|
||||
Return<Result> activate(int32_t sensor_handle, bool enabled) override;
|
||||
|
||||
Return<void> poll(int32_t maxCount, poll_cb _hidl_cb) override;
|
||||
|
||||
Return<Result> batch(
|
||||
int32_t sensor_handle,
|
||||
int64_t sampling_period_ns,
|
||||
int64_t max_report_latency_ns) override;
|
||||
Return<Result> batch(int32_t sensor_handle, int64_t sampling_period_ns,
|
||||
int64_t max_report_latency_ns) override;
|
||||
|
||||
Return<Result> flush(int32_t sensor_handle) override;
|
||||
|
||||
Return<Result> injectSensorData(const Event& event) override;
|
||||
|
||||
Return<void> registerDirectChannel(
|
||||
const SharedMemInfo& mem, registerDirectChannel_cb _hidl_cb) override;
|
||||
Return<void> registerDirectChannel(const SharedMemInfo& mem,
|
||||
registerDirectChannel_cb _hidl_cb) override;
|
||||
|
||||
Return<Result> unregisterDirectChannel(int32_t channelHandle) override;
|
||||
|
||||
Return<void> configDirectReport(
|
||||
int32_t sensorHandle, int32_t channelHandle, RateLevel rate,
|
||||
configDirectReport_cb _hidl_cb) override;
|
||||
Return<void> configDirectReport(int32_t sensorHandle, int32_t channelHandle, RateLevel rate,
|
||||
configDirectReport_cb _hidl_cb) override;
|
||||
|
||||
private:
|
||||
private:
|
||||
static constexpr int32_t kPollMaxBufferSize = 128;
|
||||
status_t mInitCheck;
|
||||
sensors_module_t *mSensorModule;
|
||||
sensors_poll_device_1_t *mSensorDevice;
|
||||
sensors_module_t* mSensorModule;
|
||||
sensors_poll_device_1_t* mSensorDevice;
|
||||
std::mutex mPollLock;
|
||||
|
||||
int getHalDeviceVersion() const;
|
||||
|
||||
static void convertFromSensorEvents(
|
||||
size_t count, const sensors_event_t *src, hidl_vec<Event> *dst);
|
||||
static void convertFromSensorEvents(size_t count, const sensors_event_t* src,
|
||||
hidl_vec<Event>* dst);
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(Sensors);
|
||||
};
|
||||
|
||||
extern "C" ISensors *HIDL_FETCH_ISensors(const char *name);
|
||||
extern "C" ISensors* HIDL_FETCH_ISensors(const char* name);
|
||||
|
||||
} // namespace implementation
|
||||
} // namespace V1_0
|
||||
|
|
|
|||
Loading…
Reference in a new issue