sensor hal log等级的设置
什么个逻辑可以动态控制log等
const char SENSORS_HAL_PROP_DEBUG[] = "persist.vendor.debug.sensors.hal";
/* map debug property value to log_level */
static const unordered_map<char, sensors_log::log_level> log_level_map = {
{ '0', sensors_log::SILENT },
{ '1', sensors_log::INFO },
{ 'e', sensors_log::ERROR },
{ 'E', sensors_log::ERROR },
{ 'i', sensors_log::INFO },
{ 'I', sensors_log::INFO },
{ 'd', sensors_log::DEBUG },
{ 'D', sensors_log::DEBUG },
{ 'v', sensors_log::VERBOSE },
{ 'V', sensors_log::VERBOSE },
};
void sensors_hal::get_system_config()
{
char debug_prop[PROPERTY_VALUE_MAX];
int len;
len = property_get(SENSORS_HAL_PROP_DEBUG, debug_prop, "i");
if (len > 0) {
if (log_level_map.find(debug_prop[0]) != log_level_map.end()) {
_sysconfig.log_level = log_level_map.at(debug_prop[0]);
}
}
sns_logi("log_level: %d", _sysconfig.log_level);
}
ActivityManager 监听UidObserver事件:gone/idle/active/unknow
void SensorService::onFirstRef() {
// Start watching UID changes to apply policy.
mUidPolicy->registerSelf();
}
void SensorService::UidPolicy::registerSelf() {
ActivityManager am;
am.registerUidObserver(this, ActivityManager::UID_OBSERVER_GONE
| ActivityManager::UID_OBSERVER_IDLE
| ActivityManager::UID_OBSERVER_ACTIVE,
ActivityManager::PROCESS_STATE_UNKNOWN,
String16("android"));
}
UidActive/UidIdle对应的处理函数
void SensorService::UidPolicy::onUidActive(uid_t uid) {
{
Mutex::Autolock _l(mUidLock);
mActiveUids.insert(uid);
}
sp<SensorService> service = mService.promote();
if (service != nullptr) {
service->setSensorAccess(uid, true);
}
}
void SensorService::UidPolicy::onUidIdle(uid_t uid, __unused bool disabled) {
bool deleted = false;
{
Mutex::Autolock _l(mUidLock);
if (mActiveUids.erase(uid) > 0) {
deleted = true;
}
}
if (deleted) {
sp<SensorService> service = mService.promote();
if (service != nullptr) {
service->setSensorAccess(uid, false);
}
}
}
最终调用函数 setSensorAccess:
void SensorService::setSensorAccess(uid_t uid, bool hasAccess) {
ConnectionSafeAutolock connLock = mConnectionHolder.lock(mLock);
for (const sp<SensorEventConnection>& conn : connLock.getActiveConnections()) {
if (conn->getUid() == uid) {
conn->setSensorAccess(hasAccess);
}
}
}
void SensorService::SensorEventConnection::setSensorAccess(const bool hasAccess) {
Mutex::Autolock _l(mConnectionLock);
mHasSensorAccess = hasAccess;
}
来着sensor数据是否发往app的判断
// Send our events to clients. Check the state of wake lock for each client and release the// lock if none of the clients need it.bool needsWakeLock = false;for (const sp<SensorEventConnection>& connection : activeConnections) {connection->sendEvents(mSensorEventBuffer, count, mSensorEventScratch,mMapFlushEventsToConnections);needsWakeLock |= connection->needsWakeLock();// If the connection has one-shot sensors, it may be cleaned up after first trigger.// Early check for one-shot sensors.if (connection->hasOneShotSensors()) {cleanupAutoDisabledSensorLocked(connection, mSensorEventBuffer, count);}}
如果没有数据上传的app如睡眠唤醒后,就要查数据上报的流程,也就是UidActive/idle的代码。这里没有太明白还要再清楚些。
睡眠唤醒相关的代码只是控制了数据上传的控制变量,并没有向sensor发送什么。
当睡眠唤醒时,SEE sensor会收到event?
发现一个诡异的现象,当android wear手表放在链接器上,不会上报重复的数据,而不连接链接器放置就会上报重复的数据。