ReactiveNetwork
ReactiveNetwork copied to clipboard
Doze mode
Right now it doesn't take doze mode into account. You could add a receiver with a https://developer.android.com/reference/android/os/PowerManager.html#ACTION_DEVICE_IDLE_MODE_CHANGED intent filter. And check doze status via PowerManager.isDeviceIdleMode() method.
Thanks for reporting this issue! I'll take a look on that. Moreover, PR with this improvement is also welcome.
I think, this functionality should be configurable and disabled by default as this project is a library.
Okay, I will take a look into it. Should I create a new NetworkObservingStrategy like for M and above?
I think, in this case, there is no need for additional strategy. Strategies are for different Android versions because, in different OS versions, network monitoring should be implemented in a different way. There should be a new library setting.
I think, there should be a new method like:
Observable<Connectivity> observeNetworkConnectivity(Context context, boolean isActiveInDozeMode)
and
Observable<Connectivity> observeNetworkConnectivity(Context context, NetworkObservingStrategy strategy, boolean isActiveInDozeMode)
The first method should use the second one.
If the user would like to, he or she can activate or explicitly deactivate network monitoring in doze mode.
Moreover, I see ACTION_DEVICE_IDLE_MODE_CHANGED
is available from API 23, so it can be implemented only in LollipopNetworkStrategy
, because it won't work in PreLollipopNetworkStrategy
anyway.
I think we have a misunderstanding. There might be no internet connection in Doze mode, so ReactiveNetwork should trigger connectivity change because ConnectivityManager may return that we are connected when in fact we are not because of idle mode.
Now, I understand your point better. Is it possible to trigger connectivity change in idle mode? Proposal with the additional receiver will trigger a change when device idle mode will change. This behavior is independent of connectivity change.
I googled more about this issue. I'm not sure if it's possible to trigger network change in a doze (idle) mode and it may be an Android bug or intended behavior. I've found the following thread on StackOverflow: http://stackoverflow.com/a/34380449/1150795.
Proposal with the additional receiver will trigger a change when device idle mode will change.
What's wrong with it? We can't make a network call in Doze mode, so we can report that we are offline no matter what ConnectivityManager says.
That sounds more reasonable if we know for sure that network call cannot be done in Doze mode. In such case, the additional broadcast receiver makes sense. Nevertheless, I would create an additional setting for that in the case someone doesn't care about Doze mode. Such feature would be useful for apps using background services and should be configurable.
@pwittchen so it seems there is another one broadcast being sent about light idle mode android.os.PowerManager#ACTION_LIGHT_DEVICE_IDLE_MODE_CHANGED
. Can I submit a PR to fix this?
Hi,
It should be already fixed for the latest Android version.
Regards
03.11.2017 10:53 PM "Alexander Perfilyev" [email protected] napisał(a):
@pwittchen https://github.com/pwittchen so it seems there is another one broadcast being sent about light idle mode android.os.PowerManager# ACTION_LIGHT_DEVICE_IDLE_MODE_CHANGED. Can I submit a PR to fix this?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/pwittchen/ReactiveNetwork/issues/115#issuecomment-341836398, or mute the thread https://github.com/notifications/unsubscribe-auth/AAqcF0kSP9ZVTQfswLX9H4wH7wZvtnFCks5sy4svgaJpZM4Kf-h6 .
@pwittchen As I see in the source, it listens only for PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED
which is deep doze mode.
This is still not working properly.
Simple test:
- Install app on emulator using this library
- adb shell dumpsys deviceidle enable
- adb shell dumpsys battery unplug
- adb shell dumpsys deviceidle force-idle
CODE:
ReactiveNetwork
.observeNetworkConnectivity(context)
.subscribe({ connectivity ->
val isConnected = connectivity.state().ordinal == NetworkInfo.State.CONNECTED.ordinal
Log.d(LOG_TAG, "Connectivity available? $isConnected")
}, {
Log(LOG_TAG, it, "Connectivity query failed")
isConnected = false
}
LOG RESULT:
system_process D/ConnectivityService: Returning BLOCKED NetworkInfo to uid=10085
com.my.app D/Application: ConnectivityHandler [T# main] | Connectivity available? false
system_process D/ConnectivityService: Returning UNBLOCKED NetworkInfo to uid=10085
Thanks for reporting this. I'll have a look on that. I'm also open for PRs related with this issue.
We are also experiencing the same problem. There is also a related issue on the google bug tracker (see here). @neteinstein have you meanwhile found a workaround? I am thinking about doing an extra ping check if the status DISCONNECTED/BLOCKED is returned.
Maybe this problem can be fixed by solving #318
@juliankotrba Not really. After a few attempts I stopped using this.
@neteinstein thanks for your answer. Have you made a custom implementation or did you switch to an alternative library?
@juliankotrba Custom implementation.
If you're looking for an alternative: Merlin lib from novoda seems to work with Doze.