sm8450-common: sensors: Cleanup code and drop unused dependencies
Change-Id: I553fb6f441cde1d3a5c4b19e42e3bd696a92bbd3
This commit is contained in:
@@ -7,32 +7,27 @@
|
||||
#define LOG_TAG "NonUiNotifier"
|
||||
|
||||
#include <android-base/logging.h>
|
||||
#include <android-base/properties.h>
|
||||
#include <android-base/unique_fd.h>
|
||||
|
||||
#include <android/frameworks/sensorservice/1.0/ISensorManager.h>
|
||||
#include <android/frameworks/sensorservice/1.0/types.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <poll.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <string>
|
||||
|
||||
#include "xiaomi_touch.h"
|
||||
|
||||
#define SENSOR_TYPE_XIAOMI_SENSOR_NONUI 33171027
|
||||
#define SENSOR_NAME_XIAOMI_SENSOR_NONUI "xiaomi.sensor.nonui"
|
||||
|
||||
using ::android::frameworks::sensorservice::V1_0::IEventQueue;
|
||||
using ::android::frameworks::sensorservice::V1_0::IEventQueueCallback;
|
||||
using ::android::frameworks::sensorservice::V1_0::ISensorManager;
|
||||
using ::android::frameworks::sensorservice::V1_0::Result;
|
||||
using ::android::hardware::Return;
|
||||
using ::android::hardware::Void;
|
||||
using ::android::hardware::sensors::V1_0::Event;
|
||||
using ::android::hardware::sensors::V1_0::SensorType;
|
||||
|
||||
using android::sp;
|
||||
using android::frameworks::sensorservice::V1_0::IEventQueue;
|
||||
using android::frameworks::sensorservice::V1_0::IEventQueueCallback;
|
||||
using android::frameworks::sensorservice::V1_0::ISensorManager;
|
||||
using android::frameworks::sensorservice::V1_0::Result;
|
||||
using android::hardware::Return;
|
||||
using android::hardware::Void;
|
||||
using android::hardware::sensors::V1_0::Event;
|
||||
using android::hardware::sensors::V1_0::SensorFlagBits;
|
||||
using android::hardware::sensors::V1_0::SensorInfo;
|
||||
using android::hardware::sensors::V1_0::SensorType;
|
||||
|
||||
#define TOUCH_DEV_PATH "/dev/xiaomi-touch"
|
||||
#define TOUCH_MAGIC 'T'
|
||||
@@ -62,13 +57,8 @@ static bool readBool(int fd) {
|
||||
|
||||
struct NonUiSensorCallback : IEventQueueCallback {
|
||||
Return<void> onEvent(const Event& e) {
|
||||
/* handle sensor event e */
|
||||
LOG(ERROR) << "onEvent scalar: " << e.u.scalar;
|
||||
bool nonUi = e.u.scalar == 1;
|
||||
|
||||
// android::base::unique_fd touch_fd_;
|
||||
// touch_fd_ = android::base::unique_fd(open(TOUCH_DEV_PATH, O_RDWR));
|
||||
|
||||
int buf[MAX_BUF_SIZE] = {0, Touch_Nonui_Mode, nonUi ? 2 : 0};
|
||||
ioctl(open(TOUCH_DEV_PATH, O_RDWR), TOUCH_IOC_SET_CUR_VALUE, &buf);
|
||||
|
||||
@@ -79,9 +69,13 @@ struct NonUiSensorCallback : IEventQueueCallback {
|
||||
} // namespace
|
||||
|
||||
int main() {
|
||||
Result res;
|
||||
sp<IEventQueue> queue;
|
||||
|
||||
sp<ISensorManager> manager = ISensorManager::getService();
|
||||
if (manager == nullptr) {
|
||||
LOG(ERROR) << "failed to get ISensorManager";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
int32_t sensorHandle = -1;
|
||||
@@ -90,13 +84,12 @@ int main() {
|
||||
sensorHandle = info.sensorHandle;
|
||||
});
|
||||
|
||||
sp<IEventQueue> queue;
|
||||
Result res;
|
||||
manager->createEventQueue(new NonUiSensorCallback(), [&queue, &res](const auto& q, auto r) {
|
||||
queue = q;
|
||||
res = r;
|
||||
});
|
||||
if (res != Result::OK) {
|
||||
LOG(ERROR) << "failed to create event queue";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
@@ -121,7 +114,6 @@ int main() {
|
||||
|
||||
while (true) {
|
||||
int rc = poll(pollfds, paths.size(), -1);
|
||||
LOG(ERROR) << "poll: " << rc;
|
||||
if (rc < 0) {
|
||||
LOG(ERROR) << "failed to poll, err: " << rc;
|
||||
continue;
|
||||
@@ -129,7 +121,7 @@ int main() {
|
||||
|
||||
for (size_t i = 0; i < paths.size(); ++i) {
|
||||
if (pollfds[i].revents & (POLLERR | POLLPRI)) {
|
||||
LOG(ERROR) << "Event on " << paths[i];
|
||||
LOG(VERBOSE) << "polled change on " << paths[i];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,7 +129,6 @@ int main() {
|
||||
for (size_t i = 0; i < paths.size(); ++i) {
|
||||
enabled = enabled || readBool(pollfds[i].fd);
|
||||
}
|
||||
LOG(ERROR) << "got notified about poll, enabled: " << enabled;
|
||||
if (enabled) {
|
||||
res = queue->enableSensor(sensorHandle, 20000 /* sample period */, 0 /* latency */);
|
||||
if (res != Result::OK) {
|
||||
|
Reference in New Issue
Block a user