Battery Optimizations whitelist not preventing Doze from deferring my app

722 views Asked by At

My app sends GPS location data to my server every 15 minutes. This functionality is the central purpose of the app.

However, the GPS logging tapers off when the phone is turned off and not in use. Time between GPS records is 15 minutes for a while, then 1 hour, 2 hours, 4 hours, 6 hours, then back to 15 minutes when I move the phone or turn it on.

This seems to be due to the Doze mode that was introduced in Android 6. I added the app to the Battery Optimizations whitelist, but that didn't make a difference, despite the documentation claiming otherwise.

  1. Why does the whitelist not help in this case?
  2. What should I be doing instead? Would a Wakelock at regular intervals delay and thus prevent Doze?

    // Request frequent location updates.
    Intent locationUpdateIntent = new Intent(this, StoreLocationService.class);
    locationUpdateIntent.setAction(MyAwesomeActionName);
    
    LocationRequest locationRequest = LocationRequest.create();
    locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    locationRequest.setInterval(15 * 60 * 1000); // 15 minutes
    locationRequest.setFastestInterval(15 * 60 * 1000); // 15 minutes
    
    LocationServices.FusedLocationApi.requestLocationUpdates(
            mGoogleApiClient, locationRequest,
            PendingIntent.getService(this, 0, locationUpdateIntent, 0));
    
1

There are 1 answers

0
paperduck On BEST ANSWER

Whitelist allows network but still blocks some CPU activity. Use setAlarmAndAllowWhileIdle() to grant CPU use for a whitelisted app.

More options are mentioned in this documentation:

https://developer.android.com/training/monitoring-device-state/doze-standby.html#understand_app_standby