当前位置: 代码网 > it编程>编程语言>Asp > Android开发sensor旋转屏问题解决示例

Android开发sensor旋转屏问题解决示例

2024年05月15日 Asp 我要评论
一、查询 activity xml 配置screenorientation信息:找个测试机器,安装此app。as中 devices explorer界面中打开此apk安装目录,双击apk。或者把apk

一、查询 activity xml 配置screenorientation信息:

找个测试机器,安装此app。as中 devices explorer界面中打开此apk安装目录,双击apk。或者把apk托到as中,在反编译的资产xml文件搜索此activity,并查看 android:screenorientation 属性。或者使用 aapt dump xmltree 命令查看。

configchanges 属性是为了防止重启activity

  <activity
            android:theme="@ref/0x7f130170"
            android:label="@ref/0x7f1200c6"
            android:name="com.miui.gallery.activity.externalphotopageactivity"
            android:screenorientation="4"
            android:configchanges="0xda0"
            android:showwhenlocked="true">

二、事件发生时间点分析:

事件发生时间点=录屏文件名的时间 + 录屏发生时视频经过的秒数

结合问题描述和usagestats服务的信息倒推事件发生时间点

三、logcat查看sensor激活状态:

此log是高通 sensors-hal 层打印的

状态栏--控制按钮--“方向锁定” 开启时,en=0 即 sensor关闭!

/vendor/qcom/proprietary/sensors-see/sensors-hal-2.0/framework/sensors_hal.cpp

logcat中搜索 device_orientation

2021-08-09 17:07:23.037 1021-1021/? i/sensors-hal: activate:209, android.sensor.device_orientation/272 en=1
2021-08-09 17:07:23.048 1021-1021/? i/sensors-hal: activate:220, android.sensor.device_orientation/272 en=1 completed

四、查看app是否注册旋转屏sensor

有的app注册的是加速度sensor,使用自己的算法计算

app注册 android.view.orientationeventlistener 回调,自身代码调节旋转demo:

    private void registerorientation(){
        orientationeventlistener orientationlistener = new orientationeventlistener(this) {
            @override
            public void onorientationchanged(int orientation) {
                log.d(tag, "onorientationchanged: " + orientation);
                if (orientation == orientationeventlistener.orientation_unknown) {
                    return; // 手机平放时,检测不到有效的角度
                }
                // 设置竖屏
                if (((orientation >= 0) && (orientation <= 30)) || (orientation >= 330)) {
                    setrequestedorientation(activityinfo.screen_orientation_portrait);
                }
                // 设置横屏
                else if (((orientation >= 230) && (orientation <= 310))) {
                    setrequestedorientation(activityinfo.screen_orientation_landscape);
                }
            }
        };
        orientationlistener.enable();
    }

五、sensorservice 信息

dump of service critical sensorservice:

bugreport dumpsys sensorservice信息查看 注册的sensor信息

previous registrations:
17:57:12 + 0x0000002d pid=20420 uid=10265 package=android.view.orientationeventlistener samplingperiod=200000us batchingperiod=0us
17:57:12 + 0x0000002d pid=20420 uid=10265 package=android.view.orientationeventlistener samplingperiod=200000us batchingperiod=0us

相关sensor:

// 加速计传感器	handle: 0x0100000b
// app通常会注册回调 android.view.orientationeventlistener 此类内部注册了 加速计sensor,用来监听旋转角度
// android.sensor.accelerometer
public static final int type_accelerometer = 1;	  
0x0100000b) lsm6dso accelerometer non-wakeup | stmicro         | ver: 142870 | type: android.sensor.accelerometer(1) | perm: n/a | flags: 0x00000980
	continuous | minrate=1.00hz | maxrate=415.97hz | fifo (max,reserved) = (10000, 3000) events | non-wakeup | 
	highest rate level = 3, support shared mem: gralloc,
0x0100015f) lsm6dso accelerometer-uncalibrated non-wakeup | stmicro         | ver: 142870 | type: android.sensor.accelerometer_uncalibrated(35) | perm: n/a | flags: 0x00000980
	continuous | minrate=1.00hz | maxrate=415.97hz | fifo (max,reserved) = (10000, 3000) events | non-wakeup | 
	highest rate level = 3, support shared mem: gralloc, 
0x5f676273) gyroscope bias (debug)    | aosp            | ver: 1 | type: android.sensor.accelerometer(1) | perm: n/a | flags: 0x00000000
	continuous | maxdelay=0us | maxrate=415.97hz | no batching | non-wakeup | 
// 方向传感器---用户app旋转屏   handle:	0x0100010f
// android.sensor.device_orientation
public static final int type_device_orientation = 27;
0x0100010f) device_orient  non-wakeup | xiaomi          | ver: 1 | type: android.sensor.device_orientation(27) | perm: n/a | flags: 0x00000002
	on-change | maxdelay=0us | mindelay=0us | fifo (max,reserved) = (10000, 0) events | non-wakeup | 
// 其 wakeup handle:  0x01000110   com.android.server.policy.windoworientationlistener 注册此类型
0x01000110) device_orient  wakeup     | xiaomi          | ver: 1 | type: android.sensor.device_orientation(27) | perm: n/a | flags: 0x00000003
	on-change | maxdelay=0us | mindelay=0us | fifo (max,reserved) = (10000, 0) events | wakeup | 

bugreport device_orient 信息查看上报事件

# 0 表示通常的正常
# 1 表示顺时针旋转90度
device_orient  wakeup: last 10 events
	 1 (ts=68477.447943014, wall=17:49:58.724) 0.00, 
	 2 (ts=68478.554363222, wall=17:49:59.831) 0.00, 
	 3 (ts=68478.989033691, wall=17:50:00.265) 0.00, 
	 4 (ts=68479.423711660, wall=17:50:00.701) 1.00, 
	 5 (ts=68482.743111608, wall=17:50:04.022) 0.00, 
	 6 (ts=68486.101931400, wall=17:50:07.379) 0.00, 
	 7 (ts=68495.309003118, wall=17:50:16.585) 0.00, 
	 8 (ts=68505.308247806, wall=17:50:26.584) 1.00, 
	 9 (ts=68507.166153170, wall=17:50:28.444) 0.00, 
	10 (ts=68513.214244108, wall=17:50:34.491) 0.00, 

六、有现场,查看当前activity信息

logcat查看当前activity: 有很多其他日志可供查看

07-31 17:50:25.687563  4486  4486 d nav_recentsimpl: onresumed classname=com.miui.gallery.activity.externalphotopageactivity,misinanotherpro=false,iskeyguardlocked=false,mnavstubview=com.miui.home.recents.navstubview{f994da4 g.e...... ......i. 0,0-1080,35}

根据dump of service usagestats:内容 查看时间点的app

    time="2021-07-08 09:29:02" type=activity_paused package=com.ainemo.dragoon class=com.meeting.call.activity.xylinkmeetingactivity instanceid=40437940 taskrootpackage=com.ainemo.dragoon taskrootclass=com.ainemo.android.activity.mainactivity flags=0x0 
log的结尾:
  in-memory daily stats
  timerange="2021/8/21 08:14–18:08" 
    packages

现场,命令方式查询当前activity:

adb shell dumpsys window | findstr mcurrentfocus
dumpsys window | grep  mcurrentfocus

查看包信息

adb shell dumpsys package com.eg.android.alipaygphone
$ adb shell dumpsys package com.android.stk
packages:
  package [com.android.stk] (ac39f18):
    userid=1001
    shareduser=sharedusersetting{411f5ce android.uid.phone/1001}
    pkg=package{fde9cef com.android.stk}
    codepath=/system/app/stk            
    resourcepath=/system/app/stk      # apk 安装包位置
    legacynativelibrarydir=/system/app/stk/lib
    extractnativelibs=true
    primarycpuabi=null
    secondarycpuabi=null
    cpuabioverride=null
    versioncode=31 minsdk=31 targetsdk=31
    minextensionversions=[]
    versionname=12                    # 版本号
    usesnonsdkapi=true
    splits=[base]
    apksigningversion=3
    applicationinfo=packageimpl{fde9cef com.android.stk}
    flags=[ system has_code allow_clear_user_data allow_backup ]
    privateflags=[ private_flag_activities_resize_mode_resizeable_via_sdk_version allow_audio_playback_capture default_to_device_protected_storage direct_boot_aware private_flag_allow_native_heap_pointer_tagging ]
    forcequeryable=false
    queriespackages=[]
    datadir=/data/user_de/0/com.android.stk  # 数据目录
    supportsscreens=[small, medium, large, xlarge, resizeable, anydensity] ############
    timestamp=2009-01-01 08:00:00
    firstinstalltime=2009-01-01 08:00:00    # 首次安装时间
    lastupdatetime=2009-01-01 08:00:00      # 上次更新时间
    signatures=packagesignatures{573d3fc version:3, signatures:[b4addb29], past signatures:[]}
    installpermissionsfixed=false
    pkgflags=[ system has_code allow_clear_user_data allow_backup ]

查看apk内部 androidmanifest.xml

aapt dump xmltree c:\users\lish\desktop\test.apk androidmanifest.xml

七、app写旋转屏的几种方式:

三种方式做旋转屏:

大部分都是直接使用系统控制的,就是systemserver进程注册的 com.android.server.policy.windoworientationlistener 监听,然后直接控制app的界面旋转,这个使用的 device_orient sensor。 但是因手机不同,厂商不同,有些竖直反向的旋转,系统不准旋转。

// frameworks/base/services/core/java/com/android/server/wm/displayrotation.java
// 内部类: displayrotation.orientationlistener
private class orientationlistener extends windoworientationlistener
//  在systemserver进程中是通过 com.android.server.wm.displayrotation$orientationlistener 操作
  • 因此,大部分视频app又会独立注册 android.view.orientationeventlistener 监听,这个监听直接使用的加速度sensor(android.sensor.accelerometer) 这个sensor直接返回0~360度的角度。然后app根据角度,自己控制旋转。此时“方向锁定”不起作用。
  • app直接使用 地磁+加速度 传感器

八、bugreport 中 muserrotation 信息

adb shell dumpsys window displays

dumpsys window displays | grep displayrotation -a 30

文件中搜索 muserrotation=

window manager display contents (dumpsys window displays)
  displayrotation
    mcurrentapporientation=screen_orientation_portrait
    mlastorientation=1
    mrotation=0 mdeferredrotationpausecount=0
    mlandscaperotation=rotation_90 mseascaperotation=rotation_270
    mportraitrotation=rotation_0 mupsidedownrotation=rotation_180
    msupportautorotation=true
    windoworientationlistener
      menabled=false
      mcurrentrotation=rotation_0
      msensortype=null
      msensor={sensor name="device_orient  wakeup", vendor="xiaomi", version=1, type=27, maxrange=1.0, resolution=1.0, power=0.001, mindelay=0}
      mrate=2
      orientationsensorjudge
        mdesiredrotation=-1
        mproposedrotation=-1
        mtouching=false   # 触摸屏幕情况下,不调用 displayrotation.java$orientationlistener 中的 onproposedrotationchanged 方法。即不会旋转
        mtouchendedtimestampnanos=617520702367  # 抬起手时,机器开机以来的时间  如果当前时间
    mcardockrotation=-1 mdeskdockrotation=-1
    muserrotationmode=user_rotation_locked muserrotation=rotation_90 mallowallrotations=false  # 正常 muserrotationmode=user_rotation_locked muserrotation=rotation_0
    mdemohdmirotation=rotation_90 mdemohdmirotationlock=false mundockedhdmirotation=-1
    mlidopenrotation=-1
    mfixedtouserrotation=false

九、setting信息查询 没大用,只能查当前信息

d:\&gt;adb shell  "dumpsys settings | grep rotation"
_id:109 name:user_rotation pkg:android value:0 default:0 defaultsystemset:true
_id:17 name:accelerometer_rotation pkg:android value:0 default:0 defaultsystemset:true
# /frameworks/base/core/java/android/provider/settings.java   accelerometer_rotation 
# 0 表示 加速度sensor 不会用于控制屏幕方向, 1 反之.
_id:108 name:hide_rotation_lock_toggle_for_accessibility pkg:com.android.systemui value:0 default:0 defaultsystemset:true

bugreport 中:

dump of service settings:

十、用户点击状态栏“锁定旋转”行为分析:

  • bugreport 搜索 devicestatemonitor:

分析用户旋转屏时间点

      ++++++++++++++++++++++++++++++++
      devicestatemonitor:
        mistetheringon=false
        misscreenon=true
        mischarging=false
        mispowersaveon=false
        mislowdataexpected=false
        miscarmodeon=false
        munsolicitedresponsefilter=127
        miswificonnected=true
        misalwayssignalstrengthreportingenabled=false
        local logs:
          2021-08-22t13:15:02.576 - screen on for display=display id 0: displayinfo{"内置屏幕", displayid 0, flag_secure, flag_supports_protected_buffers, flag_trusted, real 1080 x 2400, largest app 2320 x 2276, smallest app 1080 x 956, appvsyncoff 1000000, presdeadline 13333332, mode 3, defaultmode 1, modes [{id=1, width=1080, height=2400, fps=60.000004}, {id=2, width=1080, height=2400, fps=144.00002}, {id=3, width=1080, height=2400, fps=120.00001}, {id=4, width=1080, height=2400, fps=90.0}], hdrcapabilities hdrcapabilities{msupportedhdrtypes=[2, 3, 4], mmaxluminance=420.0, mmaxaverageluminance=210.1615, mminluminance=0.323}, minimalpostprocessingsupported false, rotation 0, state on}, displaymetrics{density=2.75, width=1080, height=2276, scaleddensity=2.75, xdpi=394.705, ydpi=394.307}, isvalid=true
          2021-08-22t13:15:03.023 - screen on for display=display id 0: displayinfo{"内置屏幕", displayid 0, flag_secure, flag_supports_protected_buffers, flag_trusted, real 1080 x 2400, largest app 2320 x 2276, smallest app 1080 x 956, appvsyncoff 1000000, presdeadline 13333332, mode 3, defaultmode 1, modes [{id=1, width=1080, height=2400, fps=60.000004}, {id=2, width=1080, height=2400, fps=144.00002}, {id=3, width=1080, height=2400, fps=120.00001}, {id=4, width=1080, height=2400, fps=90.0}], hdrcapabilities hdrcapabilities{msupportedhdrtypes=[2, 3, 4], mmaxluminance=420.0, mmaxaverageluminance=210.1615, mminluminance=0.323}, minimalpostprocessingsupported false, rotation 0, state on}, displaymetrics{density=2.75, width=1080, height=2276, scaleddensity=2.75, xdpi=394.705, ydpi=394.307}, isvalid=true
          2021-08-22t13:15:42.385 - wifi (default) connected
          ...............
      ++++++++++++++++++++++++++++++++
      transportmanager:
  • bugreport 搜索 buffer qslog:
  • 分析 用户点击 “方向锁定” 时间点
  • 现场执行命令: dumpsys activity service com.android.systemui/.dump.systemuiauxiliarydumpservice
    buffer qslog:
    ============================================================================
    12-22 14:48:42.160 v qslog: [custom(com.miui.securitycenter/com.miui.superpower.notification.superpowertileservice)] tile updated. label=超级省电. state=1. icon=null.
    12-22 14:48:42.160 v qslog: [custom(com.milink.service/com.milink.ui.service.milinktileservice)] tile updated. label=投屏. state=1. icon=null.
    12-22 14:48:42.160 v qslog: [custom(com.miui.mishare.connectivity/.tile.misharetileservice)] tile updated. label=小米互传. state=1. icon=null.
    12-22 16:50:34.787 verbose qslog [rotation] tile updated. label=方向锁定. state=2. icon=resourceicon[resid=0x7f0805a0].
    12-22 16:51:07.775 debug qslog [rotation] tile clicked. statusbarstate=shd. tilestate=active
    12-22 16:51:07.790 verbose qslog [rotation] tile updated. label=方向锁定. state=1. icon=resourceicon[resid=0x7f0805a1].
  • label=方向锁定. state=2 表示 锁定
  • logcat 搜索 “ send click msg ” 状态栏点击事件
  • android_util_seemplog.cpp 这个高通的log似乎未起作用

十一、app调用 setrequestedorientation 请求变更activity方向配置

需要自己写打点log

x、一些知识点:

亮屏是否默认开启旋转屏sensor: 锁定旋转后,device_orient 这个sensor是否一直处于 enable状态,google 默认开启

/frameworks/base/core/java/android/provider/settings.java

        /**
         * the default state of show_rotation_suggestions.
         * @hide
         */
        public static final int show_rotation_suggestions_default =
                // show_rotation_suggestions_enabled;
                show_rotation_suggestions_disabled;

以上就是android开发sensor旋转屏问题解决示例的详细内容,更多关于android sensor旋转屏的资料请关注代码网其它相关文章!

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com