Android開發(fā)sensor旋轉(zhuǎn)屏問題解決示例
一、查詢 activity xml 配置screenOrientation信息:
找個測試機器,安裝此APP。as中 devices explorer界面中打開此apk安裝目錄,雙擊apk?;蛘甙補pk托到as中,在反編譯的資產(chǎn)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">
二、事件發(fā)生時間點分析:
事件發(fā)生時間點=錄屏文件名的時間 + 錄屏發(fā)生時視頻經(jīng)過的秒數(shù)
結(jié)合問題描述和usagestats服務(wù)的信息倒推事件發(fā)生時間點
三、logcat查看sensor激活狀態(tài):
此log是高通 sensors-hal 層打印的
狀態(tài)欄--控制按鈕--“方向鎖定” 開啟時,en=0 即 sensor關(guān)閉!
/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是否注冊旋轉(zhuǎn)屏sensor
有的APP注冊的是加速度sensor,使用自己的算法計算
APP注冊 android.view.OrientationEventListener 回調(diào),自身代碼調(diào)節(jié)旋轉(zhuǎn)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; // 手機平放時,檢測不到有效的角度 } // 設(shè)置豎屏 if (((orientation >= 0) && (orientation <= 30)) || (orientation >= 330)) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } // 設(shè)置橫屏 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
相關(guān)sensor:
// 加速計傳感器 handle: 0x0100000b // app通常會注冊回調(diào) android.view.OrientationEventListener 此類內(nèi)部注冊了 加速計sensor,用來監(jiān)聽旋轉(zhuǎn)角度 // 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旋轉(zhuǎn)屏 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 表示順時針旋轉(zhuǎn)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,
六、有現(xiàn)場,查看當(dāng)前activity信息
logcat查看當(dāng)前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}
根據(jù)DUMP OF SERVICE usagestats:內(nèi)容 查看時間點的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的結(jié)尾: In-memory daily stats timeRange="2021/8/21 08:14–18:08" packages
現(xiàn)場,命令方式查詢當(dāng)前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 # 數(shù)據(jù)目錄 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內(nèi)部 AndroidManifest.xml
aapt dump xmltree C:\Users\lish\Desktop\test.apk AndroidManifest.xml
七、App寫旋轉(zhuǎn)屏的幾種方式:
三種方式做旋轉(zhuǎn)屏:
大部分都是直接使用系統(tǒng)控制的,就是SystemServer進程注冊的 com.android.server.policy.WindowOrientationListener 監(jiān)聽,然后直接控制APP的界面旋轉(zhuǎn),這個使用的 device_orient sensor。 但是因手機不同,廠商不同,有些豎直反向的旋轉(zhuǎn),系統(tǒng)不準(zhǔn)旋轉(zhuǎn)。
// frameworks/base/services/core/java/com/android/server/wm/DisplayRotation.java // 內(nèi)部類: DisplayRotation.OrientationListener private class OrientationListener extends WindowOrientationListener // 在systemserver進程中是通過 com.android.server.wm.DisplayRotation$OrientationListener 操作
- 因此,大部分視頻app又會獨立注冊 android.view.OrientationEventListener 監(jiān)聽,這個監(jiān)聽直接使用的加速度sensor(android.sensor.accelerometer) 這個sensor直接返回0~360度的角度。然后APP根據(jù)角度,自己控制旋轉(zhuǎn)。此時“方向鎖定”不起作用。
- 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 # 觸摸屏幕情況下,不調(diào)用 DisplayRotation.java$OrientationListener 中的 onProposedRotationChanged 方法。即不會旋轉(zhuǎn) mTouchEndedTimestampNanos=617520702367 # 抬起手時,機器開機以來的時間 如果當(dāng)前時間 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āng)前信息
D:\>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:
十、用戶點擊狀態(tài)欄“鎖定旋轉(zhuǎn)”行為分析:
- bugreport 搜索 DeviceStateMonitor:
分析用戶旋轉(zhuǎn)屏?xí)r間點
++++++++++++++++++++++++++++++++ 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{"內(nèi)置屏幕", 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{"內(nèi)置屏幕", 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:
- 分析 用戶點擊 “方向鎖定” 時間點
- 現(xiàn)場執(zhí)行命令: 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 ” 狀態(tài)欄點擊事件
- android_util_SeempLog.cpp 這個高通的log似乎未起作用
十一、app調(diào)用 setRequestedOrientation 請求變更activity方向配置
需要自己寫打點log
X、一些知識點:
亮屏是否默認(rèn)開啟旋轉(zhuǎn)屏sensor: 鎖定旋轉(zhuǎn)后,device_orient 這個sensor是否一直處于 enable狀態(tài),google 默認(rèn)開啟
/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開發(fā)sensor旋轉(zhuǎn)屏問題解決示例的詳細內(nèi)容,更多關(guān)于Android sensor旋轉(zhuǎn)屏的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
.NET?Core?分布式任務(wù)調(diào)度ScheduleMaster詳解
這篇文章主要介紹了分布式任務(wù)調(diào)度ScheduleMaster,集中任務(wù)調(diào)度系統(tǒng),最簡單的理解ScheduleMaster,就是對不同的系統(tǒng)里面的調(diào)度任務(wù)做統(tǒng)一管理的框架,本文通過圖文實例代碼相結(jié)合給大家介紹的非常詳細,需要的朋友可以參考下2022-05-05動網(wǎng)論壇的asp 數(shù)據(jù)庫連接代碼
動網(wǎng)論壇的asp程序,在一定程度了,成了asp的頂峰之作。高手2009-02-02CreateKeyWord asp實現(xiàn)的由給定的字符串生成關(guān)鍵字的代碼
CreateKeyWord asp實現(xiàn)的由給定的字符串生成關(guān)鍵字的代碼...2007-09-09