Android sensor列表和访问记录

2024-06-17 08:12

本文主要是介绍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服务的注册

在这里插入图片描述

这篇关于Android sensor列表和访问记录的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1068913

相关文章

Android实现任意版本设置默认的锁屏壁纸和桌面壁纸(两张壁纸可不一致)

客户有些需求需要设置默认壁纸和锁屏壁纸  在默认情况下 这两个壁纸是相同的  如果需要默认的锁屏壁纸和桌面壁纸不一样 需要额外修改 Android13实现 替换默认桌面壁纸: 将图片文件替换frameworks/base/core/res/res/drawable-nodpi/default_wallpaper.*  (注意不能是bmp格式) 替换默认锁屏壁纸: 将图片资源放入vendo

安卓链接正常显示,ios#符被转义%23导致链接访问404

原因分析: url中含有特殊字符 中文未编码 都有可能导致URL转换失败,所以需要对url编码处理  如下: guard let allowUrl = webUrl.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) else {return} 后面发现当url中有#号时,会被误伤转义为%23,导致链接无法访问

Android平台播放RTSP流的几种方案探究(VLC VS ExoPlayer VS SmartPlayer)

技术背景 好多开发者需要遴选Android平台RTSP直播播放器的时候,不知道如何选的好,本文针对常用的方案,做个大概的说明: 1. 使用VLC for Android VLC Media Player(VLC多媒体播放器),最初命名为VideoLAN客户端,是VideoLAN品牌产品,是VideoLAN计划的多媒体播放器。它支持众多音频与视频解码器及文件格式,并支持DVD影音光盘,VCD影

Node.js学习记录(二)

目录 一、express 1、初识express 2、安装express 3、创建并启动web服务器 4、监听 GET&POST 请求、响应内容给客户端 5、获取URL中携带的查询参数 6、获取URL中动态参数 7、静态资源托管 二、工具nodemon 三、express路由 1、express中路由 2、路由的匹配 3、路由模块化 4、路由模块添加前缀 四、中间件

android-opencv-jni

//------------------start opencv--------------------@Override public void onResume(){ super.onResume(); //通过OpenCV引擎服务加载并初始化OpenCV类库,所谓OpenCV引擎服务即是 //OpenCV_2.4.3.2_Manager_2.4_*.apk程序包,存

c++的初始化列表与const成员

初始化列表与const成员 const成员 使用const修饰的类、结构、联合的成员变量,在类对象创建完成前一定要初始化。 不能在构造函数中初始化const成员,因为执行构造函数时,类对象已经创建完成,只有类对象创建完成才能调用成员函数,构造函数虽然特殊但也是成员函数。 在定义const成员时进行初始化,该语法只有在C11语法标准下才支持。 初始化列表 在构造函数小括号后面,主要用于给

从状态管理到性能优化:全面解析 Android Compose

文章目录 引言一、Android Compose基本概念1.1 什么是Android Compose?1.2 Compose的优势1.3 如何在项目中使用Compose 二、Compose中的状态管理2.1 状态管理的重要性2.2 Compose中的状态和数据流2.3 使用State和MutableState处理状态2.4 通过ViewModel进行状态管理 三、Compose中的列表和滚动

两个月冲刺软考——访问位与修改位的题型(淘汰哪一页);内聚的类型;关于码制的知识点;地址映射的相关内容

1.访问位与修改位的题型(淘汰哪一页) 访问位:为1时表示在内存期间被访问过,为0时表示未被访问;修改位:为1时表示该页面自从被装入内存后被修改过,为0时表示未修改过。 置换页面时,最先置换访问位和修改位为00的,其次是01(没被访问但被修改过)的,之后是10(被访问了但没被修改过),最后是11。 2.内聚的类型 功能内聚:完成一个单一功能,各个部分协同工作,缺一不可。 顺序内聚:

Android 10.0 mtk平板camera2横屏预览旋转90度横屏拍照图片旋转90度功能实现

1.前言 在10.0的系统rom定制化开发中,在进行一些平板等默认横屏的设备开发的过程中,需要在进入camera2的 时候,默认预览图像也是需要横屏显示的,在上一篇已经实现了横屏预览功能,然后发现横屏预览后,拍照保存的图片 依然是竖屏的,所以说同样需要将图片也保存为横屏图标了,所以就需要看下mtk的camera2的相关横屏保存图片功能, 如何实现实现横屏保存图片功能 如图所示: 2.mtk

android应用中res目录说明

Android应用的res目录是一个特殊的项目,该项目里存放了Android应用所用的全部资源,包括图片、字符串、颜色、尺寸、样式等,类似于web开发中的public目录,js、css、image、style。。。。 Android按照约定,将不同的资源放在不同的文件夹中,这样可以方便的让AAPT(即Android Asset Packaging Tool , 在SDK的build-tools目