ASensorEventQueue_getEvents;
ASensorEventQueue_hasEvents;
ASensorEventQueue_setEventRate;
+ ASensorManager_configureDirectReport; # introduced=26
ASensorManager_createEventQueue;
+ ASensorManager_createHardwareBufferDirectChannel; # introduced=26
+ ASensorManager_createSharedMemoryDirectChannel; # introduced=26
+ ASensorManager_destroyDirectChannel; # introduced=26
ASensorManager_destroyEventQueue;
ASensorManager_getDefaultSensor;
ASensorManager_getDefaultSensorEx; # introduced=21
ASensorManager_getInstance;
+ ASensorManager_getInstanceForPackage; # introduced=26
ASensorManager_getSensorList;
ASensor_getFifoMaxEventCount; # introduced=21
ASensor_getFifoReservedEventCount; # introduced=21
+ ASensor_getHighestDirectReportRateLevel; # introduced=26
ASensor_getMinDelay;
ASensor_getName;
ASensor_getReportingMode; # introduced=21
ASensor_getStringType; # introduced=21
ASensor_getType;
ASensor_getVendor;
+ ASensor_isDirectChannelTypeSupported; # introduced=26
ASensor_isWakeUpSensor; # introduced=21
ASharedMemory_create; # introduced=26
ASharedMemory_getSize; # introduced=26
#define LOG_TAG "sensor"
#include <utils/Log.h>
+#include <android/hardware_buffer.h>
#include <android/looper.h>
#include <android/sensor.h>
-
-#include <utils/RefBase.h>
-#include <utils/Looper.h>
-#include <utils/Timers.h>
-
+#include <android/sharedmem.h>
+#include <cutils/native_handle.h>
#include <gui/Sensor.h>
#include <gui/SensorManager.h>
#include <gui/SensorEventQueue.h>
+#include <utils/Looper.h>
+#include <utils/RefBase.h>
+#include <utils/Timers.h>
#include <poll.h>
using android::String16;
/*****************************************************************************/
+#define ERROR_INVALID_PARAMETER(message) ALOGE("%s: " message, __func__)
+
+// frequently used check
+#define RETURN_IF_MANAGER_IS_NULL(retval) do {\
+ if (manager == nullptr) { \
+ ERROR_INVALID_PARAMETER("manager cannot be NULL"); \
+ return retval; \
+ } \
+ } while (false)
+#define RETURN_IF_SENSOR_IS_NULL(retval) do {\
+ if (sensor == nullptr) { \
+ ERROR_INVALID_PARAMETER("sensor cannot be NULL"); \
+ return retval; \
+ } \
+ } while (false)
+
ASensorManager* ASensorManager_getInstance()
{
return ASensorManager_getInstanceForPackage(NULL);
return 0;
}
+int ASensorManager_createSharedMemoryDirectChannel(
+ ASensorManager *manager, int fd, size_t size) {
+ RETURN_IF_MANAGER_IS_NULL(android::BAD_VALUE);
+
+ if (fd < 0) {
+ ERROR_INVALID_PARAMETER("fd is invalid.");
+ return android::BAD_VALUE;
+ }
+
+ if (size < sizeof(ASensorEvent)) {
+ ERROR_INVALID_PARAMETER("size has to be greater or equal to sizeof(ASensorEvent).");
+ }
+
+ native_handle_t *resourceHandle = native_handle_create(1 /* nFd */, 0 /* nInt */);
+ if (!resourceHandle) {
+ return android::NO_MEMORY;
+ }
+
+ resourceHandle->data[0] = fd;
+ int ret = static_cast<SensorManager *>(manager)->createDirectChannel(
+ size, ASENSOR_DIRECT_CHANNEL_TYPE_SHARED_MEMORY, resourceHandle);
+ native_handle_delete(resourceHandle);
+ return ret;
+}
+
+int ASensorManager_createHardwareBufferDirectChannel(
+ ASensorManager *manager, AHardwareBuffer const *buffer, size_t size) {
+ RETURN_IF_MANAGER_IS_NULL(android::BAD_VALUE);
+
+ if (buffer == nullptr) {
+ ERROR_INVALID_PARAMETER("buffer cannot be NULL");
+ return android::BAD_VALUE;
+ }
+
+ if (size < sizeof(ASensorEvent)) {
+ ERROR_INVALID_PARAMETER("size has to be greater or equal to sizeof(ASensorEvent).");
+ }
+
+ const native_handle_t *resourceHandle = AHardwareBuffer_getNativeHandle(buffer);
+ if (!resourceHandle) {
+ return android::NO_MEMORY;
+ }
+
+ return static_cast<SensorManager *>(manager)->createDirectChannel(
+ size, ASENSOR_DIRECT_CHANNEL_TYPE_HARDWARE_BUFFER, resourceHandle);
+}
+
+void ASensorManager_destroyDirectChannel(ASensorManager *manager, int channelId) {
+ RETURN_IF_MANAGER_IS_NULL(void());
+
+ static_cast<SensorManager *>(manager)->destroyDirectChannel(channelId);
+}
+
+int ASensorManager_configureDirectReport(
+ ASensorManager *manager, ASensor const *sensor, int channelId, int rate) {
+ RETURN_IF_MANAGER_IS_NULL(android::BAD_VALUE);
+
+ int sensorHandle;
+ if (sensor == nullptr) {
+ if (rate != ASENSOR_DIRECT_RATE_STOP) {
+ ERROR_INVALID_PARAMETER(
+ "sensor cannot be null when rate is not ASENSOR_DIRECT_RATE_STOP");
+ return android::BAD_VALUE;
+ }
+ sensorHandle = -1;
+ } else {
+ sensorHandle = static_cast<Sensor const *>(sensor)->getHandle();
+ }
+ return static_cast<SensorManager *>(manager)->configureDirectChannel(
+ channelId, sensorHandle, rate);
+}
+
/*****************************************************************************/
int ASensorEventQueue_registerSensor(ASensorEventQueue* queue, ASensor const* sensor,
{
return static_cast<Sensor const*>(sensor)->isWakeUpSensor();
}
+
+bool ASensor_isDirectChannelTypeSupported(ASensor const *sensor, int channelType) {
+ RETURN_IF_SENSOR_IS_NULL(false);
+ return static_cast<Sensor const *>(sensor)->isDirectChannelTypeSupported(channelType);
+}
+
+int ASensor_getHighestDirectReportRateLevel(ASensor const *sensor) {
+ RETURN_IF_SENSOR_IS_NULL(ASENSOR_DIRECT_RATE_STOP);
+ return static_cast<Sensor const *>(sensor)->getHighestDirectReportRateLevel();
+}