mehrvarz / webcall-android

WebCall for Android - Web-Telephony P2P Messaging File-Exchange E2E-Encryption No-SIM
GNU General Public License v3.0
128 stars 14 forks source link

Websocket communication issue / cannot receive calls in deep sleep #5

Closed mehrvarz closed 2 years ago

mehrvarz commented 2 years ago

When looking at the live server logs I notice a small number of devices running into a Websocket timeout. This happens while all other devices work perfectly in parallel.

Description: WebCall app connects to WebCall server. The connection succeed, but at some point the client is unable to communicate with the server and the server logs a timeout. Due to the asynchronous nature of this, the server is unable to notify the device and the user may not be aware of the issue. At this point the app is disconnected and is NOT able to receive calls.

Solution: Make sure that Battery optimization (under Settings/Apps) is turned off ("Unrestricted") for WebCall app. WebCall implements it's own power optimizations internally. It cannot receive calls if it is cut off the network (by the OS) while in deep sleep.

You also need to permit WebCall to "always run in the background". This DOES NOT mean that WebCall will actually always run in the background. It means that it "can" run when it needs to. WebCall needs this permission to be able to reconnect when the network connection has gone away. When WebCall makes use of this, it does so for a split second* only. You will hardly see any additional battery consumption from this. Try it out.

*Edit: Turns out, immediate reconnect attempts often fail. Starting with v1.0, WebCall takes a 5 second pause before trying to reconnect. So it takes a little more time than "a split second" but still very little time wrt battery power.

If you see a status message saying "Disconnected from WebCall server.." or "WebSocket reconnect has failed", this could mean that the network connection was lost while in sleep mode.

mehrvarz commented 2 years ago

More on Battery optimizations / keep awake permission:

If you click "Go offline" in WebCall, there will be zero network activity and zero background activity going forward. I am sure there are ways (network meter) to confirm this.

If you then close WebCall (back key), WebCall service will immediately be terminated. You can verify this with "Running services" under Developer options.

If "Start on boot" is deactivated (default), WebCall will never run any code during boot or later, until you open WebCall manually.

WebCall does not sneak on you behind your back. However, Battery optimizations need to be turned off (unrestricted) for the phone feature to work as intended.

You can easily compile the APK yourself. If you want to look at how the "always run in the background" permission is used, look for keepAwakeWakeLock in the WebCall source. If you want to see how much additional time your device is being kept awake with that permission given, look for "awakeMS=xxxxx" in your adb log:

adb logcat |grep awakeMS

mehrvarz commented 2 years ago

The Keep-Awake time is now shown in WebCall for Android under Call Statistics (v1.0 rc3 and up). I would be interested to know what Keep-Awake times you see at the end of the day (before midnight).