Skip to content

fix: keep the main process active while the WebView is in the foreground - #60

Draft
ItsChaceD wants to merge 2 commits into
mainfrom
fix/RMET-5394/keep-main-process-alive
Draft

fix: keep the main process active while the WebView is in the foreground#60
ItsChaceD wants to merge 2 commits into
mainfrom
fix/RMET-5394/keep-main-process-alive

Conversation

@ItsChaceD

Copy link
Copy Markdown
Contributor

⚠️ CLAUDE ASSISTED PR

Description

Bind the isolated WebView activity to a small service that lives in the main app process, for as long as the browser is open.

Since the WebView moved to its own process, the main app process has no visible UI while the user is in the browser. Android treats it as idle and freezes it about 30 seconds into a browser session. A frozen main process can't run the app's event handlers, so pages like payment callbacks load in the browser but the app never reacts and never closes it. On stock Android the process thaws when an event arrives, so it recovers. Vendor freezers like Samsung's don't thaw, which leaves users stuck on a blank page. Connecting a USB cable disables Samsung's freezing, which is why the problem never reproduced while capturing logs.

The service binding makes Android treat the main process as active while the browser is visible, so it never becomes freezable. The binding only happens in the isolated process; the sharing (in-process) variant doesn't need it.

Context

https://outsystemsrd.atlassian.net/browse/RMET-5394

Type of changes

  • Fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Refactor (cosmetic changes)
  • Breaking change (change that would cause existing functionality to not work as expected)

@OS-pedrogustavobilro OS-pedrogustavobilro left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR doesn't seem bad according to some docs

However, this issue (assuming it's the same issue) seemed to have happened with older versions before the WebView activity moved to its own process, so it's hard to say if this PR would actually fix anything.

Be that as it may, we should keep it open for now, and see if we can reproduce the actual issue and then check if this fix helps at all.

PS: Left a minor comment

Comment on lines +198 to +199
bindService(Intent(this, OSIABKeepAliveService::class.java), connection, Context.BIND_AUTO_CREATE)
keepAliveConnection = connection

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: In accordance to the docs https://developer.android.com/reference/android/content/Context#bindService(android.content.Intent,%20android.content.ServiceConnection,%20int), the method can throw SecurityException, and we should call unbindService in that situation (and I guess if we do we don't need to assign keepAliveConnection. Can we add that here perhaps?

I don't think we need to fail the activity on that exception, as the webview would still function as is right?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants