如何查看哪些唤醒锁处于活动状态
由于某种原因,我的 Android 手机无法进入睡眠状态。我假设唤醒锁使其保持唤醒状态,但无法判断哪些唤醒锁处于活动状态。正在运行的服务没有列出任何可疑的内容,当然也与平常没有什么不同。所以我的问题是:
当进程结束时,Android 是否一定会释放唤醒锁?是否有可能应用程序写得不好并且在退出前没有释放唤醒锁?
有什么方法可以查看活动的唤醒锁吗?
这是 dumpsys power
显示的内容:
$ dumpsys power
Power Manager State:
mIsPowered=true mPowerState=0 mScreenOffTime=226093 ms
mPartialCount=0
mWakeLockState=
mUserState=
mPowerState=
mLocks.gather=
mNextTimeout=91922738 now=92136117 -213s from now
mDimScreen=true mStayOnConditions=0
mScreenOffReason=3 mUserState=0
mBroadcastQueue={-1,-1,-1}
mBroadcastWhy={0,0,0}
mPokey=1 mPokeAwakeonSet=false
mKeyboardVisible=false mUserActivityAllowed=false
mKeylightDelay=6000 mDimDelay=47000 mScreenOffDelay=7000
mPreventScreenOn=false mScreenBrightnessOverride=-1 mButtonBrightnessOverride=-1
mScreenOffTimeoutSetting=60000 mMaximumScreenOffTimeout=2147483647
mLastScreenOnTime=0
mBroadcastWakeLock=UnsynchronizedWakeLock(mFlags=0x1 mCount=0 mHeld=false)
mStayOnWhilePluggedInScreenDimLock=UnsynchronizedWakeLock(mFlags=0x6 mCount=0 mHeld=false)
mStayOnWhilePluggedInPartialLock=UnsynchronizedWakeLock(mFlags=0x1 mCount=0 mHeld=false)
mPreventScreenOnPartialLock=UnsynchronizedWakeLock(mFlags=0x1 mCount=0 mHeld=false)
mProximityPartialLock=UnsynchronizedWakeLock(mFlags=0x1 mCount=0 mHeld=false)
mProximityWakeLockCount=0
mProximitySensorEnabled=false
mProximitySensorActive=false
mProximityPendingValue=-1
mLastProximityEventTime=0
mLightSensorEnabled=false
mLightSensorValue=-1.0 mLightSensorPendingValue=-1.0
mLightSensorScreenBrightness=35 mLightSensorButtonBrightness=255 mLightSensorKeyboardBrightness=0
mUseSoftwareAutoBrightness=true
mAutoBrightessEnabled=false
mScreenBrightness: animating=false targetValue=-1 curValue=0.0 delta=-1.3333334
mLocks.size=0:
mPokeLocks.size=1:
poke lock 'PhoneApp': POKE_LOCK_IGNORE_CHEEK_EVENTS
For some reason my Android phone won't go to sleep. I assume that a wakelock is keeping it awake, but there is no way to tell which wakelocks are active. The running services doesn't list anything suspicious, and certainly nothing different from usual. So my questions are:
Does Android definitely release wakelocks when a process ends? Is it possible an app was badly written and didn't release a wakelock before exiting?
Is there any way to see the active wakelocks?
This is what dumpsys power
shows:
$ dumpsys power
Power Manager State:
mIsPowered=true mPowerState=0 mScreenOffTime=226093 ms
mPartialCount=0
mWakeLockState=
mUserState=
mPowerState=
mLocks.gather=
mNextTimeout=91922738 now=92136117 -213s from now
mDimScreen=true mStayOnConditions=0
mScreenOffReason=3 mUserState=0
mBroadcastQueue={-1,-1,-1}
mBroadcastWhy={0,0,0}
mPokey=1 mPokeAwakeonSet=false
mKeyboardVisible=false mUserActivityAllowed=false
mKeylightDelay=6000 mDimDelay=47000 mScreenOffDelay=7000
mPreventScreenOn=false mScreenBrightnessOverride=-1 mButtonBrightnessOverride=-1
mScreenOffTimeoutSetting=60000 mMaximumScreenOffTimeout=2147483647
mLastScreenOnTime=0
mBroadcastWakeLock=UnsynchronizedWakeLock(mFlags=0x1 mCount=0 mHeld=false)
mStayOnWhilePluggedInScreenDimLock=UnsynchronizedWakeLock(mFlags=0x6 mCount=0 mHeld=false)
mStayOnWhilePluggedInPartialLock=UnsynchronizedWakeLock(mFlags=0x1 mCount=0 mHeld=false)
mPreventScreenOnPartialLock=UnsynchronizedWakeLock(mFlags=0x1 mCount=0 mHeld=false)
mProximityPartialLock=UnsynchronizedWakeLock(mFlags=0x1 mCount=0 mHeld=false)
mProximityWakeLockCount=0
mProximitySensorEnabled=false
mProximitySensorActive=false
mProximityPendingValue=-1
mLastProximityEventTime=0
mLightSensorEnabled=false
mLightSensorValue=-1.0 mLightSensorPendingValue=-1.0
mLightSensorScreenBrightness=35 mLightSensorButtonBrightness=255 mLightSensorKeyboardBrightness=0
mUseSoftwareAutoBrightness=true
mAutoBrightessEnabled=false
mScreenBrightness: animating=false targetValue=-1 curValue=0.0 delta=-1.3333334
mLocks.size=0:
mPokeLocks.size=1:
poke lock 'PhoneApp': POKE_LOCK_IGNORE_CHEEK_EVENTS
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
在新版本的 Android 中,您可以在此处查看唤醒锁列表:
In new versions of Android you can see list of wakelocks here:
您可以使用下面的 adb 命令来请求唤醒锁
然后,您可以使用下面的命令来查看该锁是否处于活动状态。您将看到时间列不断变化,这意味着唤醒锁处于活动状态
现在,使用此 adb 命令释放唤醒锁
然后,再次检查,时间列将冻结,这意味着唤醒锁处于非活动状态
您可以使用使用相同的技术来观察您在代码中获取的唤醒锁。
You can use below adb command to require a wake lock
Then, you can use below command to watch if this lock is active. You will see the time column continuously change, it means the wake lock is active
Now, use this adb command to release the wake lock
Then, check it again, the time column will freeze, it means the wake lock is non active
You can use the same technique to observe the wake lock you acquire in the code.
我对此表示怀疑,尽管我不确定。
据我所知,是的。
运行
adb shell dumpsys power
。I doubt it, though I do not know for certain.
AFAIK, yes.
Run
adb shell dumpsys power
.正如其他人已经说过的那样, adb shell dumpsys power 可以向您显示活动的唤醒锁。
但是,对于未释放唤醒锁的应用程序,按照此处的答案:
https://stackoverflow.com/a/16258624/428271
应该是Android发布的。但是,它适用于应用程序/进程被终止的情况,但它也应该适用于应用程序/进程完成时。它还提供源代码参考,而不仅仅是说“签入代码”
As others have already said, adb shell dumpsys power can show you active wakelocks.
However, for apps that didn't release wakelock, as per the answer here:
https://stackoverflow.com/a/16258624/428271
It should be released by Android. However, it is for case where app/process is killed, but it should be applicable when app/process is complete too. It also provides the source code references rather than just saying 'checked in code'
就其价值而言,在 Android 7.1.1 上,这正是我所寻找的:
For what it's worth, on Android 7.1.1 this is exactly what I was looking for:
要查看活动唤醒锁,请运行:
adb shell dumpsys power|grep -iwake
To see active wake-locks run :
adb shell dumpsys power|grep -i wake
您可以检查 Google Play 中提供的“Wakelock Detector”应用程序,
它有一个简单的 UI,显示每个应用程序获取的唤醒锁的详细列表
正如您所提到的,它在顶部显示活动的正在运行的应用程序,目前可能存在唤醒锁。
唤醒锁检测器
You can check "Wakelock Detector" app which is available in Google Play
It has a simple UI which shows detail list of acquired wakelocks per each application
and as you mentioned, it shows active running apps on the top, which might have wakelock present at the moment.
Wakelock detector
当进程结束时,Android 不会释放唤醒锁。它应该在结束之前由进程显式释放。
Android does not release wakelocks when the process ends. It should be explicitly released by the process before ending.