Android sensor列表和访问记录

命令:
dumpsys sensorservice

1.dumpsys sensorservice查看最近申请记录

dumpsys sensorservice命令输出Previous Registrations.

Previous Registrations:
23:07:43 + 0x00000008 pid=16587 uid=10397 package=com.start.testdemo.ui.udfp.fql.XsqFQLActivity samplingPeriod=66667us batchingPeriod=0us
23:07:41 - 0x00000008 pid=16587 uid=10397 package=com.start.testdemo.ui.udfp.fql.XsqFQLActivity
23:07:01 + 0x00000008 pid=16587 uid=10397 package=com.start.testdemo.ui.udfp.fql.XsqFQLActivity samplingPeriod=66667us batchingPeriod=0us
23:06:48 - 0x00000008 pid=16587 uid=10397 package=com.start.testdemo.ui.udfp.fql.XsqFQLActivity
23:06:47 + 0x00000008 pid=16587 uid=10397 package=com.start.testdemo.ui.udfp.fql.XsqFQLActivity samplingPeriod=66667us batchingPeriod=0us
23:06:15 - 0x00000008 pid=16587 uid=10397 package=com.start.testdemo.ui.udfp.fql.XsqFQLActivity
23:06:13 + 0x00000008 pid=16587 uid=10397 package=com.start.testdemo.ui.udfp.fql.XsqFQLActivity samplingPeriod=66667us batchingPeriod=0us
23:06:11 - 0x00000008 pid=16587 uid=10397 package=com.start.testdemo.ui.udfp.fql.XsqFQLActivity
23:06:11 + 0x00000008 pid=16587 uid=10397 package=com.start.testdemo.ui.udfp.fql.XsqFQLActivity samplingPeriod=66667us batchingPeriod=0us
21:19:08 - 0x00000001 pid= 3725 uid=10372 package=org.qiyi.basecore.widget.shakeguide.b
21:19:05 - 0x00000001 pid= 3725 uid=10372 package=org.qiyi.basecore.widget.shakeguide.b
21:19:05 + 0x00000001 pid= 3725 uid=10372 package=org.qiyi.basecore.widget.shakeguide.b samplingPeriod=200000us batchingPeriod=0us
21:19:03 + 0x00000001 pid= 3725 uid=10372 package=org.qiyi.basecore.widget.shakeguide.b samplingPeriod=200000us batchingPeriod=0us
21:18:28 - 0x00000001 pid=22095 uid=10339 package=dib.a

以上输出可以看出最近申请sensor的记录的PID, UID, 以及访问的组件package, 以及访问的sensor handle.

2.dumpsys sensorservice查看设备中所有的sensor信息

Sensor Device:
Total 6 h/w sensors, 6 running 0 disabled clients:
0x00000001) active-count = 1; sampling_period(ms) = {200.0}, selected = 200.00 ms; batching_period(ms) = {2000.0}, selected = 2000.00 ms
0x00000005) active-count = 2; sampling_period(ms) = {1000.0, 200.0}, selected = 200.00 ms; batching_period(ms) = {0.0, 0.0}, selected = 0.00 ms
0x00000008) active-count = 1; sampling_period(ms) = {66.7}, selected = 66.67 ms; batching_period(ms) = {0.0}, selected = 0.00 ms
Sensor List:
0x00000001) ACCELEROMETER             | stk8ba58        | ver: 1 | type: android.sensor.accelerometer(1) | perm: n/a | flags: 0x00000000continuous | minRate=1.00Hz | maxRate=100.00Hz | no batching | non-wakeUp | 
0x00000002) MAGNETOMETER              | MTK             | ver: 1 | type: android.sensor.magnetic_field(2) | perm: n/a | flags: 0x00000000continuous | minRate=5.00Hz | maxRate=50.00Hz | FIFO (max,reserved) = (4500, 600) events | non-wakeUp | 
0x00000003) ORIENTATION               | MTK             | ver: 1 | type: android.sensor.orientation(3) | perm: n/a | flags: 0x00000000continuous | minRate=50.00Hz | maxRate=200.00Hz | no batching | non-wakeUp | 
0x00000005) LIGHT                     | MTK             | ver: 1 | type: android.sensor.light(5) | perm: n/a | flags: 0x00000002on-change | minRate=1.00Hz | minDelay=0us | no batching | non-wakeUp | 
0x00000008) PROXIMITY                 | MTK             | ver: 1 | type: android.sensor.proximity(8) | perm: n/a | flags: 0x00000003on-change | minRate=1.00Hz | minDelay=0us | FIFO (max,reserved) = (4500, 100) events | wakeUp | 
0x0000001b) DEVICE_ORIENTATION        | MTK             | ver: 1 | type: android.sensor.device_orientation(27) | perm: n/a | flags: 0x00000002on-change | minRate=1.00Hz | minDelay=0us | no batching | non-wakeUp | 
0x5f67656f) GeoMag Rotation Vector Sensor | AOSP            | ver: 3 | type: android.sensor.geomagnetic_rotation_vector(20) | perm: n/a | flags: 0x00000000continuous | maxDelay=0us | maxRate=100.00Hz | no batching | non-wakeUp | 
Fusion States:

从以上可知,本机一共有6个sensor, 被禁的为0.
Total 6 h/w sensors, 6 running 0 disabled clients:

其中每条输出内容如下:
以light-sensor为例,

0x00000005) LIGHT                     | MTK             | ver: 1 | type: android.sensor.light(5) | perm: n/a | flags: 0x00000002on-change | minRate=1.00Hz | minDelay=0us | no batching | non-wakeUp |

其输出的对应的各个字段声明如下:

  1. 0x00000005 // handle that identifies this sensors. 唯一标识符.
  2. MTK // sensor制造商Mediatek
  3. ver:1 //表示版本号
  4. type:android.sensor.light(5) // 表示light type sensor
  5. perm:n/a // 需要的访问权限,n/a表示无.
  6. flags:0x00000002 // 2表示上报方式是on_change.
  7. on-change //表示sensor数据发生变化才触发listener回调.
  8. non-wakeUp // 表示此sensor非wake up型sensor. 即light-sensor不会因为光线变化数据变化而主动唤醒屏幕.

http://aospxref.com/android-14.0.0_r2/xref/hardware/libhardware/include/hardware/sensors.h
文件中的sensor_t 结构体.


struct sensor_t {/* Name of this sensor.* All sensors of the same "type" must have a different "name".*/const char*     name;/* vendor of the hardware part */const char*     vendor;/* version of the hardware part + driver. The value of this field* must increase when the driver is updated in a way that changes the* output of this sensor. This is important for fused sensors when the* fusion algorithm is updated.*/int             version;/* handle that identifies this sensors. This handle is used to reference* this sensor throughout the HAL API.*/int             handle;/* this sensor's type. */int             type;/* maximum range of this sensor's value in SI units */float           maxRange;/* smallest difference between two values reported by this sensor */float           resolution;/* rough estimate of this sensor's power consumption in mA */float           power;/* this value depends on the reporting mode:**   continuous: minimum sample period allowed in microseconds*   on-change : 0*   one-shot  :-1*   special   : 0, unless otherwise noted*/int32_t         minDelay;/* number of events reserved for this sensor in the batch mode FIFO.* If there is a dedicated FIFO for this sensor, then this is the* size of this FIFO. If the FIFO is shared with other sensors,* this is the size reserved for that sensor and it can be zero.*/uint32_t        fifoReservedEventCount;/* maximum number of events of this sensor that could be batched.* This is especially relevant when the FIFO is shared between* several sensors; this value is then set to the size of that FIFO.*/uint32_t        fifoMaxEventCount;/* type of this sensor as a string.** If type is OEM specific or sensor manufacturer specific type* (>=SENSOR_TYPE_DEVICE_PRIVATE_BASE), this string must be defined with reserved domain of* vendor/OEM as a prefix, e.g. com.google.glass.onheaddetector** For sensors of Android defined types, Android framework will override this value. It is ok to* leave it pointing to an empty string.*/const char*    stringType;/* permission required to see this sensor, register to it and receive data.* Set to "" if no permission is required. Some sensor types like the* heart rate monitor have a mandatory require_permission.* For sensors that always require a specific permission, like the heart* rate monitor, the android framework might overwrite this string* automatically.*/const char*    requiredPermission;/* This value is defined only for continuous mode and on-change sensors. It is the delay between* two sensor events corresponding to the lowest frequency that this sensor supports. When lower* frequencies are requested through batch()/setDelay() the events will be generated at this* frequency instead. It can be used by the framework or applications to estimate when the batch* FIFO may be full.** NOTE: 1) period_ns is in nanoseconds where as maxDelay/minDelay are in microseconds.*              continuous, on-change: maximum sampling period allowed in microseconds.*              one-shot, special : 0*   2) maxDelay should always fit within a 32 bit signed integer. It is declared as 64 bit*      on 64 bit architectures only for binary compatibility reasons.* Availability: SENSORS_DEVICE_API_VERSION_1_3*/#ifdef __LP64__int64_t maxDelay;#elseint32_t maxDelay;#endif/* Flags for sensor. See SENSOR_FLAG_* above. Only the least significant 32 bits are used here.* It is declared as 64 bit on 64 bit architectures only for binary compatibility reasons.* Availability: SENSORS_DEVICE_API_VERSION_1_3*/#ifdef __LP64__uint64_t flags;#elseuint32_t flags;#endif/* reserved fields, must be zero */void*           reserved[2];
};

struct sensor_t结构体的数据对接HAL层的SensorInfo的结构体, 数据来源于HAL层的注册.

http://aospxref.com/android-14.0.0_r2/xref/hardware/interfaces/sensors/1.0/types.hal

struct SensorInfo {/*** handle that identifies this sensors. This handle is used to reference* this sensor throughout the HAL API.*/int32_t sensorHandle;/*** Name of this sensor.* All sensors of the same "type" must have a different "name".*/string name;/** vendor of the hardware part */string vendor;/*** version of the hardware part + driver. The value of this field* must increase when the driver is updated in a way that changes the* output of this sensor. This is important for fused sensors when the* fusion algorithm is updated.*/int32_t version;/** this sensor's type. */SensorType type;/*** type of this sensor as a string.** When defining an OEM specific sensor or sensor manufacturer specific* sensor, use your reserve domain name as a prefix.* e.g. com.google.glass.onheaddetector** For sensors of known type defined in SensorType (value <* SensorType::DEVICE_PRIVATE_BASE), this can be an empty string.*/string typeAsString;/** maximum range of this sensor's value in SI units */float maxRange;/** smallest difference between two values reported by this sensor */float resolution;/** rough estimate of this sensor's power consumption in mA */float power;/*** this value depends on the reporting mode:**   continuous: minimum sample period allowed in microseconds*   on-change : 0*   one-shot  :-1*   special   : 0, unless otherwise noted*/int32_t minDelay;/*** number of events reserved for this sensor in the batch mode FIFO.* If there is a dedicated FIFO for this sensor, then this is the* size of this FIFO. If the FIFO is shared with other sensors,* this is the size reserved for that sensor and it can be zero.*/uint32_t fifoReservedEventCount;/*** maximum number of events of this sensor that could be batched.* This is especially relevant when the FIFO is shared between* several sensors; this value is then set to the size of that FIFO.*/uint32_t fifoMaxEventCount;/*** permission required to see this sensor, register to it and receive data.* Set to "" if no permission is required. Some sensor types like the* heart rate monitor have a mandatory require_permission.* For sensors that always require a specific permission, like the heart* rate monitor, the android framework might overwrite this string* automatically.*/string requiredPermission;/*** This value is defined only for continuous mode and on-change sensors.* It is the delay between two sensor events corresponding to the lowest* frequency that this sensor supports. When lower frequencies are requested* through batch()/setDelay() the events will be generated at this frequency* instead.* It can be used by the framework or applications to estimate when the* batch FIFO may be full.** NOTE: periodNs is in nanoseconds where as maxDelay/minDelay are in*       microseconds.**       continuous, on-change: maximum sampling period allowed in*                              microseconds.**          one-shot, special : 0*/int32_t maxDelay;/** Bitmask of SensorFlagBits */bitfield<SensorFlagBits> flags;
};

以上dump输出对应代码:
/android-14.0.0_r2/xref/frameworks/native/services/sensorservice/SensorList.cpp
在这里插入图片描述

3.当前正在被访问的sensor

Active sensors:
ACCELEROMETER (handle=0x00000001, connections=1)
LIGHT (handle=0x00000005, connections=2)
PROXIMITY (handle=0x00000008, connections=1)
Socket Buffer size = 984 events
WakeLock Status: not held 
Mode : NORMAL
Sensor Privacy: disabled
4 active connections
Connection Number: 0 Operating Mode: NORMALc.d.a.b.b | WakeLockRefCount 0 | uid 1000 | cache size 0 | max cache size 0LIGHT 0x00000005 | status: active | pending flush events 0 
Connection Number: 1 Operating Mode: NORMALcom.android.server.power.FaceDownDetector | WakeLockRefCount 0 | uid 1000 | cache size 0 | max cache size 0ACCELEROMETER 0x00000001 | status: active | pending flush events 0 
Connection Number: 2 Operating Mode: NORMALcom.xsq.server.display.XsqWidgetObserver | WakeLockRefCount 0 | uid 1000 | cache size 0 | max cache size 0LIGHT 0x00000005 | status: active | pending flush events 0 
Connection Number: 3 Operating Mode: NORMALcom.start.testdemo.ui.udfp.fql.XsqFQLActivity | WakeLockRefCount 0 | uid 10397 | cache size 0 | max cache size 0PROXIMITY 0x00000008 | status: active | pending flush events 0 
0 direct connections

从以上可知,在执行dumpsys sensorservice时刻,有三个sensor正在被监听工作状态.
其中Proximity-sensor正在被自写的测试APP(com.start.testdemo)持有.

4.Psensor PROXIMITY_SCREEN_OFF_WAKE_LOCK用法

自研程序可以通过申请PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK来实现亮灭屏.

demo

    @Overrideprotected void onCreate(@Nullable Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.udfp_quick_launch_layout);PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);if (powerManager.isWakeLockLevelSupported(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK)) {// 可以控制屏幕亮灭,只是关闭屏幕背光,不会导致PowerManagerService和通知PhoneWindowManager进行锁屏通知mProximitySensorWakeLock = powerManager.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, "SensorTestActivity:mProximitySensorWakeLock");}}private PowerManager.WakeLock mProximitySensorWakeLock;private void enableProximitySensor() {if (null == mProximitySensorWakeLock) {return;}if (!mProximitySensorWakeLock.isHeld()) {Log.d(TAG, "enableProximitySensor: acquiring proximity wake lock");mProximitySensorWakeLock.acquire();} else {Log.d(TAG, "enableProximitySensor: proximity sensor is held.");}}private void disableProximitySensor() {if (null == mProximitySensorWakeLock) {return;}if (mProximitySensorWakeLock.isHeld()) {Log.d(TAG, "disableProximitySensor: release proximity wake lock");mProximitySensorWakeLock.release(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK);}}

这里需要注意,申请该WAKE_LOCK的黑屏仅仅是关闭屏幕背光,并不会直接通知PowerManager和Keyguard去上锁屏幕.

其申请sensor的角色也变成了System_server中的DisplayPowerController.

Previous Registrations:
00:11:02 + 0x00000008 pid= 1351 uid= 1000 package=com.android.server.display.DisplayPowerController samplingPeriod=200000us batchingPeriod=0us
00:09:15 - 0x00000008 pid=16587 uid=10397 package=com.start.testdemo.ui.udfp.fql.XsqFQLActivity

4 active connections
Connection Number: 0
Operating Mode: NORMAL
com.android.server.display.DisplayPowerController | WakeLockRefCount 0 | uid 1000 | cache size 0 | max cache size 0
PROXIMITY 0x00000008 | status: active | pending flush events 0

5.sensorservice服务的注册

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/bicheng/30422.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

07.MyBatis映射器:一对一关联查询

大家好&#xff0c;我是王有志&#xff0c;一个分享硬核 Java 技术的金融摸鱼侠&#xff0c;欢迎大家加入 Java 人自己的交流群“共同富裕的 Java 人”。 《MyBatis 映射器&#xff1a;实现简单的 SQL 语句》中&#xff0c;我们在 MyBatis 映射器的查询语句中使用 resultType 元…

AMBA-CHI协议详解(四)

《AMBA 5 CHI Architecture Specification》 AMBA-CHI协议详解&#xff08;一&#xff09; AMBA-CHI协议详解&#xff08;二&#xff09; AMBA-CHI协议详解&#xff08;三&#xff09; AMBA-CHI协议详解&#xff08;四&#xff09; 文章目录 2.3.3 Atomic transactions2.3.4 S…

MySql进阶:深入理解MySQL语句执行逻辑

深入理解MySQL语句执行逻辑 一、前言 本文源自微博客(www.microblog.store),且以获得授权 一直是想知道一条SQL语句是怎么被执行的&#xff0c;它执行的顺序是怎样的&#xff0c;然后查看总结各方资料&#xff0c;就有了下面这一篇博文了。   本文将从MySQL总体架构—&…

plc如何接线

在开始前刚好我有一些资料&#xff0c;是我根据网友给的问题精心整理了一份「plc的资料从专业入门到高级教程」&#xff0c; 点个关注在评论区回复“666”之后私信回复“666”&#xff0c;全部无偿共享给大家&#xff01;&#xff01;&#xff01;PLC自动化控制在电气自动化和…

Adobe Premiere 视频编辑软件下载安装,pr 全系列资源分享!

Adobe Premiere以其强大的功能、灵活的操作和卓越的性能&#xff0c;成为视频编辑领域的佼佼者。 在剪辑方面&#xff0c;Adobe Premiere提供了强大而灵活的工具集。用户可以在直观的时间线上对视频进行精细的裁剪、剪辑和合并操作。无论是快速剪辑短片&#xff0c;还是精心打造…

springboot心理健康线上咨询系统APP-计算机毕业设计源码031539

摘 要 信息化社会内需要与之针对性的信息获取途径&#xff0c;但是途径的扩展基本上为人们所努力的方向&#xff0c;由于站在的角度存在偏差&#xff0c;人们经常能够获得不同类型信息&#xff0c;这也是技术最为难以攻克的课题。针对心理健康咨询等问题&#xff0c;对其进行研…

钡铼BL102应用智能电网配电柜PLC转MQTT无线接云服务

在当今智能电网的发展浪潮中&#xff0c;配电系统的智能化升级是提升电网效率与稳定性的重要环节。随着物联网技术的飞速发展&#xff0c;实现配电柜的远程监控与管理成为了可能&#xff0c;而这一转变的关键在于如何有效地将传统配电柜中的PLC数据接入到云端进行分析与处理。 …

大数据关联规则算法

关联性&#xff08;Association&#xff09; 定义&#xff1a;指一个变量能够提供有关另一个变量的信息。特点&#xff1a;关联性是一个广泛的概念&#xff0c;它可以包括直接的、间接的、强的或弱的联系。 相关性&#xff08;Correlation&#xff09; 定义&#xff1a;指两个…

AI视频智能监管赋能城市管理:打造安全有序的城市环境

一、方案背景 随着城市化进程的加速和科技的飞速发展&#xff0c;街道治安问题日益凸显&#xff0c;治安监控成为维护社会稳定和保障人民安全的重要手段。当前&#xff0c;许多城市已经建立了较为完善的治安监控体系&#xff0c;但仍存在一些问题。例如&#xff0c;监控设备分…

window 卸载应用商店程序

# 使用Get-AppxPackage获取所有应用程序 # 使用Remove-AppxPackage PythonSoftwareFoundation.Python.3.12_3.12.1264.0_x64__qbz5n2kfra8p0

【Linux 基础】目录结构

Linux 的目录结构&#xff08;也称为文件系统结构&#xff09;是组织文件和目录的一种逻辑方式。每个文件和目录在文件系统中都有一个唯一的位置或路径。 Linux文件系统是整个操作系统的基础架构&#xff0c;对于系统的稳定运行、数据安全以及用户操作便捷性至关重要&#xff0…

webhook-k8s API和apimachinery版本高于Client-go

1. 问题 使用go mod tidy 存在丢弃的版本 go: downloading github.com/josharian/intern v1.0.0 go: finding module for package k8s.io/api/flowcontrol/v1alpha1 go: simple-webhook/types importsk8s.io/client-go/rest tested byk8s.io/client-go/rest.test importsk8s.…

场外个股期权通道业务是什么意思?

今天带你了解场外个股期权通道业务是什么意思&#xff1f;场外个股期权业务是指在沪深交易所之外进行的个股期权交易。它是一种非标准化的合约&#xff0c;不在交易所内进行交割。 场外个股期权通道业务&#xff0c;是指投资者通过与场外个股期权机构通道签订合约&#xff0c;购…

uni-app中使用富文本rich-text个人经验

rich-text是在uni-app一个内置组件&#xff0c;用于高性能地渲染富文本内容。先贴一下官方的属性列表&#xff1a; 先说一下“selectable” 长按选择区域复制&#xff0c;这个我在APP项目中 不起作用&#xff0c;可能像文档说的&#xff0c;只支持“百度小程序”吧。在APP端起作…

CUDA系列-Mem-9

这里写目录标题 Static Architecture.Abstractions provided by CUSW_UNIT_MEM_MANAGERMemory Object (CUmemobj) Memory Descriptor(CUmemdesc)Memory Block(CUmemblock)Memory BinsSuballocations in Memory BlockFunctional description Memory Manager 你可能觉得奇怪&…

使用SQLite

自学python如何成为大佬(目录):https://blog.csdn.net/weixin_67859959/article/details/139049996?spm1001.2014.3001.5501 与许多其他数据库管理系统不同&#xff0c;SQLite不是一个客户端/服务器结构的数据库引擎&#xff0c;而是一种嵌入式数据库&#xff0c;它的数据库就…

Centos 配置安装Mysql

linux安装配置mysql的方法主要有yum安装和配置安装两种&#xff0c;由于yum安装比较简单&#xff0c;但是会将文件分散到不同的目录结构下面&#xff0c;配置起来比较麻烦&#xff0c;这里主要研究一下配置安装mysql的方法 1、环境说明 centos 7.9 mysql 5.7.372、环境检查 …

反激式开关电源是如何工作的

反激的变压器可以看作一个带变压功能的电感&#xff0c;是一个buck-boost电路。 反击式开关变压器 反激式开关电源是指使用反激高频变压器隔离输入输出回路的开关电源。“反激”指的是在开关管接通的情况下&#xff0c;当输入为高电平时输出线路中串联的电感为放电状态&#x…

ABAP-03基础数据类型

基本数据类型 数据类型默认大小&#xff08;byte&#xff09;有效大小初始值说明示例C11-65535SPACE文本字符&#xff08;串&#xff09;‘Name’N11-65535‘00…0’数字文本‘0123’T66‘000000’时间(HHMMSS)‘123010’D88‘00000000’日期(yyyymmdd)‘20090901’I4-231~232…

算法基础精选题单 动态规划(dp)(递推+线性dp)(个人题解)

前言&#xff1a; 一些简单的dp问题。 正文&#xff1a; 题单&#xff1a;237题】算法基础精选题单_ACM竞赛_ACM/CSP/ICPC/CCPC/比赛经验/题解/资讯_牛客竞赛OJ_牛客网 (nowcoder.com) 递推&#xff1a; NC235911 走楼梯&#xff1a; #include<bits/stdc.h> using na…