为什么< android/sensor.h>中缺少某些传感器的枚举值?使用它们安全吗? [英] Why enum values for some sensors are missing from <android/sensor.h>? Is it safe to use them?
问题描述
<android/sensor.h>
中似乎缺少某些传感器的枚举值.
It seems that enum values for some sensors are missing from <android/sensor.h>
.
文件定义了以下枚举:
/*
* Sensor types
* (keep in sync with hardware/sensor.h)
*/
enum {
ASENSOR_TYPE_ACCELEROMETER = 1,
ASENSOR_TYPE_MAGNETIC_FIELD = 2,
ASENSOR_TYPE_GYROSCOPE = 4,
ASENSOR_TYPE_LIGHT = 5,
ASENSOR_TYPE_PROXIMITY = 8
};
评论说此枚举与<hardware/sensor.h>
同步(未公开,它是android源代码的一部分).
The comment says that this enum is synced with <hardware/sensor.h>
(which is not exposed, it's a part of android source).
但是在<hardware/sensor.h>
中,我发现了值(例如压力,温度和湿度传感器)
But in the <hardware/sensor.h>
I've found values for many more useful sensors like pressure, temperature and humidity ones:
#define SENSOR_TYPE_ACCELEROMETER (1)
#define SENSOR_TYPE_GEOMAGNETIC_FIELD (2)
#define SENSOR_TYPE_ORIENTATION (3)
#define SENSOR_TYPE_GYROSCOPE (4)
#define SENSOR_TYPE_LIGHT (5)
#define SENSOR_TYPE_PRESSURE (6)
#define SENSOR_TYPE_TEMPERATURE (7)
#define SENSOR_TYPE_PROXIMITY (8)
#define SENSOR_TYPE_GRAVITY (9)
#define SENSOR_TYPE_LINEAR_ACCELERATION (10)
#define SENSOR_TYPE_ROTATION_VECTOR (11)
#define SENSOR_TYPE_RELATIVE_HUMIDITY (12)
// ...
#define SENSOR_TYPE_HEART_BEAT (31)
为什么某些传感器未在<android/sensor.h>
中列出?使用它们安全又便携吗?
Why some sensors are not listed in the <android/sensor.h>
? It it safe and portable to use them?
推荐答案
At the moment it is absolutely safe to use constants from <hardware/sensor.h>
since SensorManager
populates its internal sensor list with data from system-wide ISensorServer
without any remapping of type values. And ISensorServer
uses <hardware/sensor.h>
constants.
我猜NDK API公开了受约束的类型集,只是因为它有一段时间没有更新.
I guess NDK API exposes constrained type set just because it was not updated for a while.
P.S.当然,如果将来出现某种映射,事情将会被打破,但是IMO AOSP会保持不变.
P.S. Of course things will be broken if some kind of mapping arise in future, but IMO AOSP will keep it unchanged.
这篇关于为什么< android/sensor.h>中缺少某些传感器的枚举值?使用它们安全吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!