部分唤醒锁定是 PowerManager API 中的一种机制,可让开发者在设备的显示屏关闭后(无论是由于系统超时还是用户按下电源按钮)继续保持 CPU 运行。您的应用可以通过调用带有 PARTIAL_WAKE_LOCK 标志的 acquire() 或使用其他用于获取唤醒锁定的 API 来获取部分唤醒锁定。过度使用部分唤醒锁定会耗尽设备的电量,因为它会阻止设备进入低功耗状态。部分唤醒锁定仅应在必要时使用,并且在不再需要时立即释放。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Excessive partial wake locks (beta)\n\nPartial wake locks are a mechanism in the [`PowerManager`](/reference/android/os/PowerManager) API that lets\ndevelopers keep the CPU running after a device's display turns off (whether due\nto system timeout or the user pressing the power button). Your app acquires a\npartial wake lock by calling [`acquire()`](/reference/android/os/PowerManager.WakeLock#acquire()) with the [`PARTIAL_WAKE_LOCK`](/reference/android/os/PowerManager#PARTIAL_WAKE_LOCK)\nflag, or by using [other APIs that acquire wake locks](/develop/background-work/background-tasks/awake/wakelock/identify-wls).\nExcessive use of partial wake locks drains the device's battery because it\nprevents the device from entering lower power states. Partial wake locks should\nbe used only when necessary and released as soon as no longer needed.\n\nIf your app uses partial wake locks excessively, you can use the guidance in\nthis page to diagnose and fix the problem.\n\nYour feedback is a crucial part of improving our documentation. Please give us\nyour feedback using the following link:\n\n\n[Give feedback](https://docs.google.com/forms/d/e/1FAIpQLScYkStao0zVsmPay22DGqYEMJSf2Rk3SE3LnPc1lcmLjN1AiQ/viewform?usp=dialog)\n\nDetect the problem\n------------------\n\nAndroid vitals can help you find out when your app's use of partial wake locks\nis excessive.\n\n### Android vitals\n\nAndroid vitals can help improve your app's performance by [alerting you via the\nPlay Console](https://support.google.com/googleplay/android-developer/answer/9844486?) when your app's use of partial wake locks is\nexcessive.\n| **Note:** Tracking of excessive partial wake locks is **currently in beta**. The threshold numbers, relevant app states, and exceptions for behavior that has end-user benefit, are all subject to change. The beta metric does not currently make your app less discoverable on Google Play. Once the metric is out of beta, excessive partial wake lock use may impact app discoverability on Play.\n\nAndroid vitals reports partial wake lock use as **excessive** when **all of the\npartial wake locks**, added together, run for 3 or more hours in 24-hour\nperiod.\n\nAndroid vitals tracks time only if the wake lock is held when the app **is in\nthe background** and **does not have a foreground service**.\n\nAndroid vitals gives some exemptions to partial wake lock usage in scenarios\nwhere there is a clear user benefit of the partial wake lock, and there's no\nbetter way to achieve that result without the partial wake lock. In those cases,\nAndroid vitals might not count the partial wake lock time against the 3-hour\nlimit. For example, if an app is playing audio for the user, there's a clear\nbenefit to keeping the device awake and there's no way to play the audio without\nkeeping the device awake. In that case, the partial wake lock time is not\ncounted against the Android vitals.\n\nIf excessive partial wake locks occur in more than 5% of app sessions across all\ndevices in a 28-day period, it can affect your app's visibility on Play once the\nmetric is out of beta.\n\nOnce you're aware that your app has excessive partial wake locks,\nyour next step is to address the issue.\n\nFix the problem\n---------------\n\nBecause wake locks can drain the device battery, you shouldn't use wake\nlocks if there's an alternative. The\n[Choose the right API to keep the device awake](/develop/background-work/background-tasks/awake)\ndocumentation can help you find the best solution for your app.\n\nIf you do need to use a wake lock, [follow wake lock best practices](/develop/background-work/background-tasks/awake/wakelock/best-practices)\nto make sure your wake locks don't hurt device efficiency. In particular,\nmake sure every device you acquire is released, and release the lock as quickly\nas possible.\n\nAfter fixing the problem in code, you can verify your fixes by using [local\nwake lock debugging tools](/develop/background-work/background-tasks/awake/wakelock/debug-locally).\n\nSee also\n--------\n\n- [Stuck partial wake locks](/topic/performance/vitals/excessive-wakelock)\n- [Wake lock documentation](/develop/background-work/background-tasks/awake/wakelock)\n\nRecommended for you\n-------------------\n\n- Note: link text is displayed when JavaScript is off\n- [Frozen frames](/topic/performance/vitals/render#frozen-frames)\n- [Run benchmarks in Continuous Integration](/topic/performance/benchmarking/benchmarking-in-ci)\n- [Create and measure Baseline Profiles without Macrobenchmark](/topic/performance/baselineprofiles/manually-create-measure)"]]