如何查看哪些唤醒锁处于活动状态

发布于 2024-11-03 03:26:54 字数 1965 浏览 2 评论 0原文

由于某种原因,我的 Android 手机无法进入睡眠状态。我假设唤醒锁使其保持唤醒状态,但无法判断哪些唤醒锁处于活动状态。正在运行的服务没有列出任何可疑的内容,当然也与平常没有什么不同。所以我的问题是:

  1. 当进程结束时,Android 是否一定会释放唤醒锁?是否有可能应用程序写得不好并且在退出前没有释放唤醒锁?

  2. 有什么方法可以查看活动的唤醒锁吗?

这是 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:

  1. 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?

  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

呢古 2024-11-10 03:26:54

在新版本的 Android 中,您可以在此处查看唤醒锁列表:

adb shell "cat /sys/kernel/debug/wakeup_sources"

In new versions of Android you can see list of wakelocks here:

adb shell "cat /sys/kernel/debug/wakeup_sources"
无可置疑 2024-11-10 03:26:54

您可以使用下面的 adb 命令来请求唤醒锁

  adb shell "echo mylock > /sys/power/wake_lock"

然后,您可以使用下面的命令来查看该锁是否处于活动状态。您将看到时间列不断变化,这意味着唤醒锁处于活动状态

  watch -n 1 'adb shell "cat /proc/wakelocks" | grep mylock'

现在,使用此 adb 命令释放唤醒锁

  adb shell "echo mylock > /sys/power/wake_unlock"

然后,再次检查,时间列将冻结,这意味着唤醒锁处于非活动状态

  watch -n 1 'adb shell "cat /proc/wakelocks" | grep mylock'

您可以使用使用相同的技术来观察您在代码中获取的唤醒锁。

You can use below adb command to require a wake lock

  adb shell "echo mylock > /sys/power/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

  watch -n 1 'adb shell "cat /proc/wakelocks" | grep mylock'

Now, use this adb command to release the wake lock

  adb shell "echo mylock > /sys/power/wake_unlock"

Then, check it again, the time column will freeze, it means the wake lock is non active

  watch -n 1 'adb shell "cat /proc/wakelocks" | grep mylock'

You can use the same technique to observe the wake lock you acquire in the code.

梦途 2024-11-10 03:26:54

当进程结束时,Android 是否一定会释放唤醒锁?

我对此表示怀疑,尽管我不确定。

是否有可能应用程序编写得不好并且在退出之前没有释放唤醒锁?

据我所知,是的。

有什么方法可以查看活动的唤醒锁吗?

运行adb shell dumpsys power

Does Android definitely release wakelocks when a process ends?

I doubt it, though I do not know for certain.

Is it possible an app was badly written and didn't release a wakelock before exiting?

AFAIK, yes.

Is there any way to see the active wakelocks?

Run adb shell dumpsys power.

暮色兮凉城 2024-11-10 03:26:54

正如其他人已经说过的那样, 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'

动听の歌 2024-11-10 03:26:54

就其价值而言,在 Android 7.1.1 上,这正是我所寻找的:

greatqlte:/ $ dumpsys power | grep WAKE_LOCK
  PARTIAL_WAKE_LOCK              'ES Wake Lock' ACQ=-38m52s804ms LONG (uid=10275 pid=12504)                                                                                                 
  PARTIAL_WAKE_LOCK              '*net_scheduler*' ACQ=-40ms (uid=10031 pid=3026 ws=Work Source{10031 com.google.android.gms})                                                               

For what it's worth, on Android 7.1.1 this is exactly what I was looking for:

greatqlte:/ $ dumpsys power | grep WAKE_LOCK
  PARTIAL_WAKE_LOCK              'ES Wake Lock' ACQ=-38m52s804ms LONG (uid=10275 pid=12504)                                                                                                 
  PARTIAL_WAKE_LOCK              '*net_scheduler*' ACQ=-40ms (uid=10031 pid=3026 ws=Work Source{10031 com.google.android.gms})                                                               
热鲨 2024-11-10 03:26:54

要查看活动唤醒锁,请运行:

adb shell dumpsys power|grep -iwake

To see active wake-locks run :

adb shell dumpsys power|grep -i wake

绝情姑娘 2024-11-10 03:26:54

您可以检查 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

游魂 2024-11-10 03:26:54

当进程结束时,Android 不会释放唤醒锁。它应该在结束之前由进程显式释放。

Android does not release wakelocks when the process ends. It should be explicitly released by the process before ending.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文