I have a method which periodically runs to keep a network connection alive. During Doze mode, I would like to disable it from running periodically and run exactly once during a maintenance window. When the device comes out of Doze, I would like the method to be called periodically again. How can I accomplish this ?
I have registered a receiver that listens for the PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED broadcast and then calls PowerManager.isDeviceIdleMode(). However, this return false for both cases - during a maintenance window and when the device exits Doze mode. How can I differentiate between them ?