Skip to content

Conversation

@ItsChaceD
Copy link
Contributor

@ItsChaceD ItsChaceD commented Jan 19, 2026

Description

This PR implements localStorage isolation on Android API 28+ via setDataDirectorySuffix, bringing it into alignment with iOS behavior.

Due to Android system limitations, isolation can only be achieved by running the WebView in a separate :OSInAppBrowser process with a dedicated data directory suffix. This requires events to be propagated between the processes via broadcast receivers. To avoid a breaking change, we keep the class signatures the same and add a custom @RequiresEventBridgeRegistration annotation to proactively warn native library users of the new registration requirement.

Context

https://outsystemsrd.atlassian.net/browse/RMET-4918?atlOrigin=eyJpIjoiOWI4NWVmMDIwZDhhNDRmMGJhMTljMWFlNTQxYmFkZjIiLCJwIjoiaiJ9

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)

Platforms affected

  • Android
  • iOS
  • JavaScript

Comment on lines +58 to +62
val event = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
intent.getSerializableExtra(EXTRA_EVENT_DATA, OSIABEvents::class.java)
} else {
intent.getSerializableExtra(EXTRA_EVENT_DATA) as? OSIABEvents
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor: We can probably replace this with a one-liner for IntentCompat#getSerializableExtra (assuming the library already has an AndroidX dependency with the method available)

Comment on lines +71 to +75
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
appContext.registerReceiver(receiver, filter, Context.RECEIVER_NOT_EXPORTED)
} else {
appContext.registerReceiver(receiver, filter)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor: Can maybe replace this with a one-liner ContextCompat#registerReceiver (assuming the library already has an AndroidX dependency that comes with this)

const val EXTRA_EVENT_DATA = "com.outsystems.plugins.inappbrowser.osinappbrowserlib.EXTRA_EVENT_DATA"

private val _events = MutableSharedFlow<OSIABEvents>()
private val _events = MutableSharedFlow<OSIABEvents>(extraBufferCapacity = 64)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why was this added?

Comment on lines 928 to +929
OSIABEvents.postEvent(event)
OSIABEvents.broadcastEvent(this@OSIABWebViewActivity, event)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we be calling both methods here?

private var receiver: BroadcastReceiver? = null

@SuppressLint("UnspecifiedRegisterReceiverFlag")
fun registerReceiver(context: Context) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

So this is necessary because the WebView activity now runs in a separate process?

Wouldn't this be necessary for CustomTabs as well before-hand?

@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CLASS)
annotation class RequiresEventBridgeRegistration

sealed class OSIABEvents : Serializable {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Feels confusing for this class to be Serializable, subclasses have Context and Activity which are not serializable. The serialization is only relevant for the broadcast receiver, which is only called for webview, but from what I see in the PR you don't set OSIABWebViewActivity anymore for OSIABWebViewEvent.

Can you explain why you implemented it that way?

flowHelper: OSIABFlowHelperInterface,
customTabsSessionCallback: (CustomTabsSession?) -> Unit
) {
OSIABEvents.registerReceiver(context)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is being called here but broadcastEvent isn't called here, so wondering about its usefulness.

Same for OSIABCustomTabsRouterAdapter

private var receiver: BroadcastReceiver? = null

@SuppressLint("UnspecifiedRegisterReceiverFlag")
fun registerReceiver(context: Context) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wondering if we should have a way to unregister the receiver, e.g. after Close events are submitted, can we get rid of the receiver, rather than it living throughout the entire app's lifecycle?

<activity
android:name=".views.OSIABWebViewActivity"
android:exported="false"
android:process=":OSInAppBrowser"
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should make sure plugins (OutSystems especially) document this change, wouldn't be surprised if it ends up breaking existing Android apps in some unexpected way, due to the many different ways people use InAppBrowser.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually, doesn't this mean that existing apps that have cookies or local storage data for a certain webpage in InAppBrowser, will no longer have that data when they update the app to this version where the data directory changes?

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.

3 participants