Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doze mode #115

Open
aperfilyev opened this issue Oct 25, 2016 · 17 comments
Open

Doze mode #115

aperfilyev opened this issue Oct 25, 2016 · 17 comments

Comments

@aperfilyev
Copy link
Contributor

aperfilyev commented Oct 25, 2016

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.

@pwittchen
Copy link
Owner

pwittchen commented Oct 25, 2016

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.

@aperfilyev
Copy link
Contributor Author

aperfilyev commented Oct 25, 2016

Okay, I will take a look into it. Should I create a new NetworkObservingStrategy like for M and above?

@pwittchen
Copy link
Owner

pwittchen commented Oct 25, 2016

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.

@aperfilyev
Copy link
Contributor Author

aperfilyev commented Oct 25, 2016

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.

@pwittchen
Copy link
Owner

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.

@pwittchen
Copy link
Owner

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.

@aperfilyev
Copy link
Contributor Author

aperfilyev commented Oct 25, 2016

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.

@pwittchen
Copy link
Owner

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.

@aperfilyev
Copy link
Contributor Author

@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?

@pwittchen
Copy link
Owner

pwittchen commented Nov 3, 2017 via email

@aperfilyev
Copy link
Contributor Author

@pwittchen As I see in the source, it listens only for PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED which is deep doze mode.

@neteinstein
Copy link

neteinstein commented Jan 11, 2019

This is still not working properly.

Simple test:

  1. Install app on emulator using this library
  2. adb shell dumpsys deviceidle enable
  3. adb shell dumpsys battery unplug
  4. 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

@pwittchen pwittchen reopened this Jan 11, 2019
@pwittchen
Copy link
Owner

Thanks for reporting this. I'll have a look on that. I'm also open for PRs related with this issue.

@juliankotrba
Copy link

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

@neteinstein
Copy link

@juliankotrba Not really.
After a few attempts I stopped using this.

@juliankotrba
Copy link

@neteinstein thanks for your answer. Have you made a custom implementation or did you switch to an alternative library?

@neteinstein
Copy link

neteinstein commented Jun 18, 2020

@juliankotrba Custom implementation.

If you're looking for an alternative: Merlin lib from novoda seems to work with Doze.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants