[HTML payload içeriği buraya]
35.1 C
Jakarta
Monday, May 11, 2026

Tips on how to Optimize Frequent Wake Lock Use Instances


Posted by Alice Yuan, Senior Developer Relations Engineer

In recognition that extreme battery drain is prime of thoughts for Android customers, Google has been taking vital steps to assist builders construct extra power-efficient apps. On March 1st, 2026, Google Play Retailer started rolling out the wake lock technical high quality therapies to enhance battery drain. This therapy will roll out steadily to impacted apps over the next weeks. Apps that constantly exceed the “Extreme Partial Wake Lock” threshold in Android vitals may even see tangible impacts on their retailer presence, together with warnings on their retailer itemizing and exclusion from discovery surfaces similar to suggestions.

Customers may even see a warning in your retailer itemizing in case your app exceeds the unhealthy conduct threshold.

This initiative elevated battery effectivity to a core important metric alongside stability metrics like crashes and ANRs. The “unhealthy conduct threshold” is outlined as holding a non-exempted partial wake lock for at the least two hours on common whereas the display screen is off in additional than 5% of consumer classes within the previous 28 days. A wake lock is exempted if it’s a system held wake lock that provides clear consumer advantages that can’t be additional optimized, similar to audio playback, location entry, or user-initiated knowledge switch. You possibly can view the total definition of extreme wake locks in our Android vitals documentation.

As a part of our ongoing initiative to enhance battery life throughout the Android ecosystem, we now have analyzed 1000’s of apps and the way they use partial wake locks. Whereas wake locks are typically obligatory, we regularly see apps holding them inefficiently or unnecessarily, when extra environment friendly options exist. This weblog will go over the commonest eventualities the place extreme wake locks happen and our suggestions for optimizing wake locks.  We’ve already seen measurable success from companions like WHOOP, who leveraged these suggestions to optimize their background conduct.

Utilizing a foreground service vs partial wake locks

We’ve usually seen builders wrestle to grasp the distinction between two ideas when doing background execution: foreground service and partial wake locks.

A foreground service is a lifecycle API that alerts to the system that an app is performing user-perceptible work and shouldn’t be killed to reclaim reminiscence, but it surely doesn’t mechanically forestall the CPU from sleeping when the display screen turns off. In distinction, a partial wake lock is a mechanism particularly designed to maintain the CPU operating even whereas the display screen is off. 

Whereas a foreground service is commonly essential to proceed a consumer motion, a guide acquisition of a partial wake lock is just obligatory along with a foreground service during the CPU exercise. As well as, you needn’t use a wake lock should you’re already using an API that retains the machine awake. 

Consult with the stream chart in Select the correct API to maintain the machine awake to make sure you have a powerful understanding of what instrument to make use of to keep away from buying a wake lock in eventualities the place it’s not obligatory.

Third occasion libraries buying wake locks

It is not uncommon for an app to find that it’s flagged for extreme wake locks held by a third-party SDK or system API performing on its behalf. To establish and resolve these wake locks, we suggest the next steps:

  • Test Android vitals: Discover the precise identify of the offending wake lock within the extreme partial wake locks dashboard. Cross-reference this identify with the Establish wake locks created by different APIs steering to see if it was created by a identified system API or Jetpack library. Whether it is, you could must optimize your utilization of the API and might confer with the beneficial steering.

  • Seize a System Hint: If the wake lock can’t be simply recognized, reproduce the wake lock challenge regionally utilizing a system hint and examine it with the Perfetto UI. You possibly can study extra about how to do that within the Debugging different forms of extreme wake locks part of this weblog put up.

  • Consider Alternate options: If an inefficient third-party library is accountable and can’t be configured to respect battery life, take into account speaking the problem with the SDK’s house owners, discovering an alternate SDK or constructing the performance in-house.

Frequent wake lock eventualities

Under is a breakdown of a number of the particular use circumstances we now have reviewed, together with the beneficial path to optimize your wake lock implementation.

Person-Initiated Add or Obtain

Instance use circumstances: 

Tips on how to cut back wake locks: 

  • Don’t purchase a guide wake lock. As a substitute, use the Person-Initiated Knowledge Switch (UIDT) API. That is the designated path for lengthy operating knowledge switch duties initiated by the consumer, and it’s exempted from extreme wake lock calculations.

One-Time or Periodic Background Syncs

Instance use circumstances: 

Tips on how to cut back wake locks: 

  • Don’t purchase a guide wake lock. Use WorkManager configured for one-time or periodic work.  WorkManager respects system well being by batching duties and has a minimal periodic interval (quarter-hour), which is usually adequate for background updates. 

  • In case you establish wake locks created by WorkManager or JobScheduler with excessive wake lock utilization, it might be since you’ve misconfigured your employee to not full in sure eventualities. Take into account analyzing the employee cease causes, significantly should you’re seeing excessive occurrences of STOP_REASON_TIMEOUT.
workManager.getWorkInfoByIdFlow(syncWorker.id)
  .acquire { workInfo ->
      if (workInfo != null) {
        val stopReason = workInfo.stopReason
        logStopReason(syncWorker.id, stopReason)
      }
  }
  • Along with logging employee cease causes, confer with our documentation on debugging your staff. Additionally, take into account gathering and analyzing system traces to grasp when wake locks are acquired and launched.

  • Lastly, try our case examine with WHOOP, the place they had been in a position to uncover a problem with configuration of their staff and cut back their wake lock influence considerably.

Bluetooth Communication

Instance use circumstances: 

  • Companion machine app prompts the consumer to pair their Bluetooth exterior machine.

  • Companion machine app listens for {hardware} occasions on an exterior machine and consumer seen change in notification.

  • Companion machine app’s consumer initiates a file switch between the cell and bluetooth machine.

  • Companion machine app performs occasional firmware updates to an exterior machine by way of Bluetooth.

Tips on how to cut back wake locks: 

  • Use companion machine pairing to pair Bluetooth units to keep away from buying a guide wake lock throughout Bluetooth pairing. 

  • Seek the advice of the Talk within the background steering to grasp how one can do background Bluetooth communication. 

  • Utilizing WorkManager is commonly adequate if there is no such thing as a consumer influence to a delayed communication. If a guide wake lock is deemed obligatory, solely maintain the wake lock during Bluetooth exercise or processing of the exercise knowledge.

Location Monitoring

Instance use circumstances: 

  • Health apps that cache location knowledge for later add similar to plotting operating routes

  • Meals supply apps that pull location knowledge at a excessive frequency to replace progress of supply in a notification or widget UI.

Tips on how to cut back wake locks: 

  • Seek the advice of our steering to Optimize location utilization. Take into account implementing timeouts, leveraging location request batching, or using passive location updates to make sure battery effectivity.

  • When requesting location updates utilizing the FusedLocationProvider or LocationManager APIs, the system mechanically triggers a tool wake-up through the location occasion callback. This temporary, system-managed wake lock is exempted from extreme partial wake lock calculations.

  • Keep away from buying a separate, steady wake lock for caching location knowledge, as that is redundant. As a substitute, persist location occasions in reminiscence or native storage and leverage WorkManager to course of them at periodic intervals.
override enjoyable onCreate(savedInstanceState: Bundle?) {
    locationCallback = object : LocationCallback() {
        override enjoyable onLocationResult(locationResult: LocationResult?) {
            locationResult ?: return
            // System wakes up CPU for brief period
            for (location in locationResult.places){
                // Retailer knowledge in reminiscence to course of at one other time
            }
        }
    }
}

Excessive Frequency Sensor Monitoring

Instance use circumstances: 

  • Pedometer apps that passively acquire steps, or distance traveled. 

  • Security apps that monitor the machine sensors for fast modifications in actual time, to supply options similar to crash detection or fall detection.

Tips on how to cut back wake locks: 

  • If utilizing SensorManager, cut back utilization to periodic intervals and solely when the consumer has explicitly granted entry by a UI interplay. Excessive frequency sensor monitoring can drain the battery closely because of the variety of CPU wake-ups and processing that happens.

  • In case you’re monitoring step counts or distance traveled, reasonably than utilizing SensorManager, leverage Recording API or take into account using Well being Join to entry historic and aggregated machine step counts to seize knowledge in a battery-efficient method.

  • In case you’re registering a sensor with SensorManager, specify a maxReportLatencyUs of 30 seconds or extra to leverage sensor batching to reduce the frequency of CPU interrupts. When the machine is subsequently woken by one other set off similar to a consumer interplay, location retrieval, or a scheduled job, the system will instantly dispatch the cached sensor knowledge.

val accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER)

sensorManager.registerListener(this,
                 accelerometer,
                 samplingPeriodUs, // How usually to pattern knowledge
                 maxReportLatencyUs // Key for sensor batching 
              )
  • In case your app requires each location and sensor knowledge, synchronize their occasion retrieval and processing. By piggybacking sensor readings onto the temporary wake lock the system holds for location updates, you keep away from needing a wake lock to maintain the CPU awake. Use a employee or a short-duration wake lock to deal with the add and processing of this mixed knowledge.

Distant Messaging

Instance use circumstances: 

  • Video or sound monitoring companion apps that want to observe occasions that happen on an exterior machine linked utilizing a neighborhood community.

  • Messaging apps that keep a community socket reference to the desktop variant.

Tips on how to cut back wake locks: 

  • If the community occasions will be processed on the server facet, use FCM to obtain info on the shopper. It’s possible you’ll select to schedule an expedited employee if extra processing of FCM knowledge is required. 

  • If occasions have to be processed on the shopper facet by way of a socket connection, a wake lock shouldn’t be wanted to pay attention for occasion interrupts. When knowledge packets arrive on the Wi-Fi or Mobile radio, the radio {hardware} triggers a {hardware} interrupt within the type of a kernel wake lock. It’s possible you’ll then select to schedule a employee or purchase a wake lock to course of the info.

  • For instance, should you’re utilizing ktor-network to pay attention for knowledge packets on a community socket, it’s best to solely purchase a wake lock when packets have been delivered to the shopper and have to be processed.

val readChannel = socket.openReadChannel()
whereas (!readChannel.isClosedForRead) {
    // CPU can safely sleep right here whereas ready for the following packet
    val packet = readChannel.readRemaining(1024) 
    if (!packet.isEmpty) {
         // Knowledge Arrived: The system woke the CPU and we should always preserve it awake by way of guide wake lock (pressing) or scheduling a employee (non-urgent)
         performWorkWithWakeLock { 
              val knowledge = packet.readBytes()
              // Further logic to course of knowledge packets
         }
    }
}

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles