platform_device_xiaomi_sm84.../sensors/utils/SensorNotifierUtils.cpp
Arian a96665b595 sm8450-common: sensors: Add aod notifier
Change-Id: I2ba35d7b7db4e6922d83f041497fe66bf52124cb
2024-08-12 10:24:33 +02:00

57 lines
1.4 KiB
C++

/*
* Copyright (C) 2024 The LineageOS Project
*
* SPDX-License-Identifier: Apache-2.0
*/
#define LOG_TAG "SensorNotifierUtils"
#include "SensorNotifierUtils.h"
#include <android-base/logging.h>
bool readBool(int fd) {
char c;
int rc;
rc = lseek(fd, 0, SEEK_SET);
if (rc) {
LOG(ERROR) << "failed to seek fd, err: " << rc;
return false;
}
rc = read(fd, &c, sizeof(char));
if (rc != 1) {
LOG(ERROR) << "failed to read bool from fd, err: " << rc;
return false;
}
return c != '0';
}
disp_event_resp* parseDispEvent(int fd) {
disp_event header;
ssize_t headerSize = read(fd, &header, sizeof(header));
if (headerSize < sizeof(header)) {
LOG(ERROR) << "unexpected display event header size: " << headerSize;
return nullptr;
}
struct disp_event_resp* response =
reinterpret_cast<struct disp_event_resp*>(malloc(header.length));
response->base = header;
int dataLength = response->base.length - sizeof(response->base);
if (dataLength < 0) {
LOG(ERROR) << "invalid data length: " << response->base.length;
return nullptr;
}
ssize_t dataSize = read(fd, &response->data, dataLength);
if (dataSize < dataLength) {
LOG(ERROR) << "unexpected display event data size: " << dataSize;
return nullptr;
}
return response;
}