Websocket dropped when app is displaying a custom tab

I have a web socket connection in the app, the user can then go to a url displayed within a Custom tab from a link sent by the agent. Right at 3:45-4 min or so minutes the socket is dropped. What is worse is the app does not get notification of the socket failure till it comes back to the foreground. Need the socket to stay open to display some data on the custom tab secondary toolbar, when agent sends a message.

When an app is displaying a URL in a Customtabs the app should till be considered high priority . According to google
" 1. Lifecycle management: Apps launching a Custom Tab won’t be evicted by the system during the Tabs use - its importance is raised to the “foreground” level."

I don’t see this same issue happen in Pixel devices.
Also note after 4:30 of inactivity by the user the chat is ended. So Not looking for an endlessly open connection.

Why is the connection dropped so quickly?

Anyone run into it and have ideas. For the socket I use okhttp (tried setting ping on as well to see if ti helps)

Hello adev05,

Any more details about the issue? Does the issue occur after the screen remains turned off for 3-4 minutes? Does it only occur when it goes to the background or does it happen when the applicant is in forground as well? Capture the dumpstate log if possible, which should detail everything happening in the background and make it easier to find the cause behind the issue.

Samsung’s power management is more strict than stock AOSP, so I can see it freezing an application after it is sent to the background and remains in the background for a while.

Hi, there the screen is not turned off. All that happens here is that the app has launched a CustomTab (Custom tabs (Android)). So the app is still running, just that the tab is in the foreground.
I will try and grab the dumpstate tomorrow.

Hi

I created a demo app to reproduce the issue. Looks like the dumpstate is too large to attach.
dumpstate_log.txt (19.7 KB)
@EA01 let me know if you need more information, it does seem like setting up a
foreground service helps with the demo app, but we prefer not to do that, the user is technically in the app while viewing the CustomTab.

Hi adev05,

Welcome to Samsung Developers Forum.

Can you please provide us with the demo app, reproduction steps, and the complete dumpstate logs either here or on our dedicated Developer Support Portal so that we can check the issue?

Best Regards,
Mobassir Ahsan
Samsung Developer Relations.