4

I am trying to identify a single reliable callback that we get in Android when the device enters Doze mode. I tried the following:

IntentFilter filter = new IntentFilter();
filter.addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED);
registerReceiver(new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d("ajitha", "intent action=" + intent.getAction()
                + " idleMode=" + pm.isDeviceIdleMode());
    }
}, filter);
super.onResume();

In the above code sample the receiver is hit many times when the device is dozing. In my trial run, logcat showed following:

    Line 103: 08-25 15:41:21.814 I/PowerManagerService(  845): Going to sleep due to power button (uid 1000)...
    Line 114: 08-25 15:41:22.601 I/PowerManagerService(  845): Dozing...
    Line 144: 08-25 15:41:36.834 D/ajitha  ( 6985): intent action=android.os.action.DEVICE_IDLE_MODE_CHANGED idleMode=true
    Line 146: 08-25 15:41:37.458 D/ajitha  ( 6985): intent action=android.os.action.DEVICE_IDLE_MODE_CHANGED idleMode=false
    Line 150: 08-25 15:41:38.268 D/ajitha  ( 6985): intent action=android.os.action.DEVICE_IDLE_MODE_CHANGED idleMode=true
    Line 154: 08-25 15:42:08.669 D/ajitha  ( 6985): intent action=android.os.action.DEVICE_IDLE_MODE_CHANGED idleMode=false
    Line 156: 08-25 15:42:09.287 D/ajitha  ( 6985): intent action=android.os.action.DEVICE_IDLE_MODE_CHANGED idleMode=true
    Line 175: 08-25 15:42:58.935 I/PowerManagerService(  845): Waking up from dozing (uid 1000)...
    Line 200: 08-25 15:42:59.273 D/ajitha  ( 6985): intent action=android.os.action.DEVICE_IDLE_MODE_CHANGED idleMode=false

If the intent is hit so many times, I am not able to perform my actions depending on this intent. Is there any other intent that I can rely to identify the device entering doze???

Why is this intent hit so many times???

Floern
  • 33,559
  • 24
  • 104
  • 119
Ajitha
  • 717
  • 1
  • 7
  • 30
  • It is not a given that when `ACTION_DEVICE_IDLE_MODE_CHANGED` is fired, doze was either turned on or off. There are more factors that can affect idle mode – Tim Aug 26 '16 at 10:27
  • Ya... :( true.. This is more bugging with limited documentation. Do you have any idea if my application will be affected by doze mode if my application is running a foreground service. – Ajitha Aug 26 '16 at 12:00
  • Foreground services are not affected by doze – Tim Aug 26 '16 at 12:14
  • The reason this intent is hit several times is because when the device is in Doze mode, there are certain maintenance windows that run for applications to complete their sync, execute alarms, etc. and then the device goes back to doze. This maintenance window varies and every time this maintenance window runs during doze mode, this intent shall be fired. – learn_develop Jun 28 '17 at 16:50

0 Answers0